Remove everything after domain name .htaccess

Ecodor

Senior Member
Joined
Nov 5, 2017
Messages
896
Reaction score
232
Is it possible i hide/remove all URL's after my domain name?
I have 2 files index.php and index2.php i dont want them to appear in the url search bar
I want my domain to show only. `example.com`
 
Definitely possible.

Add this code to your .htaccess and restart your web server.

Code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
 
Thank you, but how do i restart my server? I am on namecheap
 
Thank you, but how do i restart my server? I am on namecheap
You can also force refresh on the webpage by pressing Ctrl + F5. Now .htaccess code will work without having to restart the webserver.
 
Nope this doesn't help. Still showing index.php & index2.php tho...
 
Nope this doesn't help. Still showing index.php & index2.php tho...
Try removing this line and access the page from another browser.

Code:
RewriteBase /
 
This is a very easy solution.

Do you want that EACH PAGE redirect to index.php

OR

index2.php redirects to index.php.

Explain clearly your needs.
 
I want both of the files to be accessible because i send the user from index.php to index2.php but i dont want any of the links to be show in the url address bar
i just want my domain to be shown.

and removing the / didnt helped
 
This is a very easy solution.

Do you want that EACH PAGE redirect to index.php

OR

index2.php redirects to index.php.

Explain clearly your needs.
My website only contains these 2 files but i can make more in future maybe... so i just want everything after my domain to be removed if is possible
 
I want both of the files to be accessible because i send the user from index.php to index2.php but i dont want any of the links to be show in the url address bar
i just want my domain to be shown.

But you can not do this!

A user has to see example.com in his address bar and not example.com/index2.php?

If you are looking for this is not possible.
 
But you can not do this!

A user has to see example.com in his address bar and not example.com/index2.php?

If you are looking for this is not possible.
Ok but can i remove index2.php only? since index.php doesnt show when user visit the page
 
Yeah, they are all in the same folder as my website
 
Ok but can i remove index2.php only? since index.php doesnt show when user visit the page

remove index2.php file from filesystem (fast solution but generate a 404 error).

or

Redirect via htacess index2 to index
 
  • Check PHP information and see if mod_rewrite module is enabed on your webserver.
  • Is the index.php created by any PHP framework or you created it manually?
 
remove index2.php file from filesystem (fast solution but generate a 404 error).

or

Redirect via htacess index2 to index
Why would i remove the index2.php file and redirect to an error? I dont get it.

Start over
lol

  • Check PHP information and see if mod_rewrite module is enabed on your webserver.
  • Is the index.php created by any PHP framework or you created it manually?
Yes the mod_rewrite is enabled by default on namecheap
Index files are created manually by me. Its just simple page where user logins on index.php and gets redirected to index2.php. but i really dont want index2.php to be visible :)
 
Back
Top