Mobile app version of vmapp.org
Login or Join
Murray432

: Simple RewriteRule I'm trying to write a RewriteRule to make a simple url. I want users to be able to type enter www.example.com/somepage and have it take them to www.example.com/abc/somepage.php

@Murray432

Posted in: #Htaccess #ModRewrite #Nginx

I'm trying to write a RewriteRule to make a simple url. I want users to be able to type enter
example.com/somepage

and have it take them to
example.com/abc/somepage.php

How can this be done in .htaccess?

I've tried these to no avail:

RewriteRule ^somepage$ abc/somepage.php [L]

RewriteRule ^/somepage$ /abc/somepage.php [L]


Your help is much appreciated.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Murray432

1 Comments

Sorted by latest first Latest Oldest Best

 

@Jamie184

Assuming this is in the .htaccess in your document root, then you are almost there. You just seem to be missing the / (slash - directory separator) from the front of your destination URL (in the first example).

RewriteEngine On
RewriteRule ^somepage$ /abc/somepage.php [R=301,L]


The slash (or whatever is the base URL) is automatically removed from the request URI when pattern matching, which is why it is not present in the pattern (^somepage$).

This will perform an external redirect (R=301) - so the destination URL will show in the browser. Remove the R flag to perform an internal rewrite (URL won't change).

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme