0

Here's an example URL to a user profile on my site: http://127.0.0.1:8080/overview/showuserprofile/user

I want it to be:

http://127.0.0.1:8080/user

This is what I have for rewrite rules:

  Options -MultiViews
  RewriteEngine On
  RewriteBase /php-login/
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-l

  RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

That gets rid of the .php at the end.

I've also tried adding

RewriteRule ^(.+)$ index.php?url=/overview/showuserprofile/$1 [QSA,L]

But the URL would change and not any of the pages.

Any ideas?

1 Answer 1

2

You will need to figure out how to differentiate user pages from other pages. Your rewrite expression ^(.+)$ matches all the pages on the site except for the home page. You will need to limit this so that it doesn't match other pages including index.php.

One way of doing so would be to only allow user pages to use lower case letter with no punctuation. Then it wouldn't match index.php due to the period. The rewrite rule for that would be:

RewriteRule ^([a-z]+)$ index.php?url=/overview/showuserprofile/$1 [QSA,L]

Another way to do it would be to check that there isn't a real file with that name as a rewrite condition using the instructions here: http://www.harecoded.com/apache-rewritecond-f-check-file-exists-solution-2246468

1
  • So by doing that and merging my other solution together they should work? So something like this? RewriteRule ^([a-z]+)$ index.php?url=/overview/showuserprofile/$1 [QSA,L]
    – John
    Commented Mar 15, 2014 at 0:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.