Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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

share|improve this answer
    
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 Mar 15 at 0:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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