Reputation: 771
I'm working on a PHP script over my localhost, and I have this code in .htaccess
RewriteEngine On
RewriteBase /Domain
#Make sure it's not an actual file
RewriteCond %{REQUEST_FILENAME} !-f
#Make sure its not a directory
RewriteCond %{REQUEST_FILENAME} !-d
#Rewrite the request to index.php
RewriteRule ^(.*)$ index.php?mode=$1 [L]
This code allows me to access this URL
http://localhost/Domain/index.php?mode=overview
as
http://localhost/Domain/overview
But I want to access this URL
http://localhost/Domain/index.php?mode=overview&s=10
as
http://localhost/Domain/overview/10
and I failed to get it :(
Please anyone can help me out on this !!
Upvotes: 1
Views: 1163
Reputation: 785471
You can use this code:
RewriteEngine On
RewriteBase /Domain/
#Make sure it's an actual file
RewriteCond %{REQUEST_FILENAME} -f [OR]
#Make sure its a directory
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
#Rewrite the request to index.php
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?mode=$1&s=$2 [L,QSA]
#Rewrite the request to index.php
RewriteRule ^([^/]+)/?$ index.php?mode=$1 [L,QSA]
Upvotes: 1
Reputation: 175
Replacing the last line of your .htaccess file with this code should do the trick.
^/(.*)/(.*)$ index.php?mode=$1&s=$2
I have not tested this, but it should work. If it does work, this is why:
It's looking for a word after the base url, in your case http://localhost/Domain/
is the base url. This match "^(.)" is captured in buffer 1, referenced as "$1". Then it wants a forward slash, followed by another capture word at the end of the url, "(.)$". This match is in capture buffer 2, "$2". If this match is found it is then rewrote to index.php with appropriate capture buffers.
Upvotes: 2
Reputation: 257
try this:
RewriteRule ^overview/([0-9]+)/$ index.php?mode=$1 [NC,L]
Upvotes: -1