: Shorten URL with Regex 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
Here's an example URL to a user profile on my site: 127.0.0.1:8080/overview/showuserprofile/user
I want it to be:
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= [QSA,L]
That gets rid of the .php at the end.
I've also tried adding
RewriteRule ^(.+)$ index.php?url=/overview/showuserprofile/ [QSA,L]
But the URL would change and not any of the pages.
Any ideas?
More posts by @Becky754
1 Comments
Sorted by latest first Latest Oldest Best
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/ [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: www.harecoded.com/apache-rewritecond-f-check-file-exists-solution-2246468
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.