-2

Ok, So iv'e decided to remove all .php extentions from the url, and for this iv'e used the simple method:

Options MultiViews+ 

However, My profile page now displays almost nothing, with a black background because of the URL. If I input:

profile.php?username=Joe.Bills 

It works perfectly fine, If however, I use:

profile?username=Joe.Bills 

It automatic changes the url and adds a / AFTER profile Example:

profile/?username=Joe.Bills 

And thus, thinking its in a "separate directory" causes the error. How can i remove it from adding the additional / so it doesn't think its going to a separate directory

P.S. My link's are correct and currently is this:

<a href="profile?username=<?php echo $_SESSION['user_name']; ?>"><span class="bg">Profile</span></a> 

Again, as I said, If I put

profile.php?username=Joe.Bills 

It works completely fine, so I don't understand why the URL thinks its a directory when entered, So my question would be:

How can I remove .PHP extensions a different way to fix this, or is there a way I can fix this with what I currently have and how?

4
  • Check stackoverflow.com/questions/8371634/… Commented May 4, 2016 at 17:39
  • You can't just remove the .php extension, you need to do some research on url rewrite. Depending on whether you are using apache or nginx you will need to figure out how to do rewrites for that individual web server. Commented May 4, 2016 at 17:40
  • I did use this too: RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [L, QSA] Commented May 4, 2016 at 17:44
  • But it gave me an internal error? Commented May 4, 2016 at 17:45

1 Answer 1

2

You can use the following instead of Options +Multiviews :

 RewriteEngine on #remove trailing slashes RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ /$1 [L,R] RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule !/$ %{REQUEST_URI}.php [NC,L] 

This will allow you to access .php files without extension/slash at the end.

Sign up to request clarification or add additional context in comments.

9 Comments

i have tried this already which did give me an internal error, though i enabled rewrite_mod on my server, and it removed the .php, however when i go to profile, it still changes it with the / so this has something to do with my request maybe for the user? but I have no clue why this is happening. I have no links that have a / in so im unsure of where the error is coming from
@Joebills any other rules in the htaccess?
Okay, So i changed the request " $name = $_REQUEST['username']; " to "$name = $_REQUEST['user'];" which then displayed as " profile?user=Joe.Bills " which worked fine, but i want it to be "username" not "user". Is there a way I could change it without the / happening again?
@JoeBills I am not good at php , not sure why the slash is appearing. Could you post your full htaccess in the question?
Ok that worked perfectly, Thank you for your help! I have no idea what or how .htaccess worked, but thank you!
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.