Reputation: 63
I can't seem to figure out how to get these conditions to happen with my .htaccess
http://example.com/index.php?page=about
to
http://example.com/about
and at the same time
http://example.com/index.php?process=login
to
http://example.com/p/login
I have tried to do this myself but I couldn't figure out how to do both at the same time.
Using Apache
Upvotes: 1
Views: 91
Reputation: 554
THE SIMPLEST CASE
The simplest case of URL rewriting is to rename a single static Web page, and this is far easier than the B&Q example above. To use Apache’s URL rewriting function, you will need to create or edit the .htaccess file in your website’s document root (or, less commonly, in a subdirectory).
RewriteEngine On
RewriteRule about index.php?page=about
RewriteRule login index.php?process=login
USING REGULAR EXPRESSIONS
In URL rewriting, you need only match the path of the URL, not including the domain name or the first slash
RewriteEngine On
RewriteRule ^about/?$ index.php?page=about [NC]
RewriteRule ^login/?$ index.php?process=login [NC]
You can also do it as
example.com/index.php?page=about
to
example.com/about.html OR example.com/about
using this rule
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /index.php?page=$1 [L]
OR
RewriteEngine On RewriteRule ^([^/]*)$ /index.php?page=$1 [L]
Here are some usefull links
Cheers!
Mudassar Ali
Upvotes: 2
Reputation: 785146
put this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^p/([^/]+)/?$ /index.php?process=$1 [L,QSA]
RewriteRule ^([^/]+)/?$ /index.php?page=$1 [L,QSA]
Upvotes: 0