I want to change/rename urls in my website. For now I'm just removing .html
in url like this:
ErrorDocument 404 /errorpage.html
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]
I want to change urls. For example: index.html -> home
, aboutus.html -> about-us
etc. I tried changing but I got server client error 500:
ErrorDocument 404 /errorpage.html
RewriteEngine on
RewriteRule ^index\.html /home [NC,L]
RewriteRule ^aboutus\.html /about-us [NC,L]
CodePudding user response:
RewriteRule ^index\.html /home [NC,L] RewriteRule ^aboutus\.html /about-us [NC,L]
It's not clear why you would get a 500 error here, unless you had combined these rules with the former rule that handled .html
extensionless URLs (this would have caused a rewrite-loop, ie. 500 error).
However, the arguments you are passing to the RewriteRule
directives are the wrong way round. You should be rewriting from /home
to /index.html
instead. The first argument matches the requested URL. The second argument (the substitution string) represents the URL (or file-path) you are rewriting to.
Your directives should be like this instead:
ErrorDocument 404 /errorpage.html
RewriteEngine on
RewriteRule ^home$ index.html [L]
RewriteRule ^about-us$ aboutus.html [L]
The slash prefix on the substitution string (second argument) is not required.
You should be linking to URLs of the form /home
and /about-us
in your HTML source and mod_rewrite internally rewrites these requests to the corresponding file that actually handles the request.