Reputation: 107
I am stuck in this .htaccess issue and not able to get a solution. Tried everything but as I am new to htaccess may be the codes are just not matching and it gives me a error.
There is a php file I am working..
This is the result I get now
http://website.com/page.php?url=diploma-in-film-acting
Now I want this to work like this
http://website.com/diploma-in-film-acting
or may be this
http://website.com/diploma-in-film-acting.html
How do I get this to work ???
I have already used this code
I already did this but I get a 404 error when I add this to the url http://website.com/diploma-in-film-acting.html
RewriteEngine On
RewriteRule ^([a-zA-Z0-9-/]+).html$ page.php?url=$1
RewriteRule ^([a-zA-Z0-9-/]+).html/$ page.php?url=$1
Thanks
Upvotes: 1
Views: 115
Reputation: 8179
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /page.php?url=$1 [L]
Upvotes: 2
Reputation: 107
It works now :-
RewriteEngine On
RewriteRule ^([a-zA-Z0-9-/]+).html$ page.php?url=$1
RewriteRule ^([a-zA-Z0-9-/]+).html/$ page.php?url=$1
Upvotes: 0
Reputation: 167172
Use mod_rewrite
of Apache! And in your .htaccess
, give this:
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /page.php?url=$1&%{QUERY_STRING} [L]
For the directory based rewriting, use this:
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /page.php?url=$1&%{QUERY_STRING} [L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ /page.phpurl$1&%{QUERY_STRING}
Optionally, if you have any query strings, that will be passed via &%{QUERY_STRING}
.
Upvotes: 1