Mobile app version of vmapp.org
Login or Join
Welton855

: Mod_rewrite with .htaccess to make dynamic page search engine friendly I am trying to make search engine friendly pages with .htaccess. The page look like /en/hotel.php?id=nice-hotel-7-patterson-street

@Welton855

Posted in: #Htaccess #ModRewrite

I am trying to make search engine friendly pages with .htaccess.

The page look like /en/hotel.php?id=nice-hotel-7-patterson-street and I would like the page to look like this /en/nice-hotel-7-patterson-street or /en/hotel-nice-hotel-7-patterson-street.

I am using this in my .htaccess file at the moment:

RewriteRule ^([a-zA-Z0-9_-]+)-([0-9]+)$ hotel.php?id= [L]


but it does not seem to work in the /en/ folder and does not seem to work if letters are in the variable.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Welton855

1 Comments

Sorted by latest first Latest Oldest Best

 

@Welton855

Your expression is incorrect. Since / is missing from the first part of the expression, it will not match anything which is in a sub-directory. Since the last expression requires there to be numbers at the end, it would work with URL that end in letters as per your examples.

You must generalize your expression, something like this:

RewriteRule ^en/([a-zA-Z0-9_-]+)$ hotel.php?id=


Now if you have multiple directories, you have to match that and pass it on somewhere different. If you have one hotel.php file in each directory use the first line below, if you have only one in all, use the second line where the directory is passed as another parameter, so that you can output different contents.

RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ /hotel.php?id=

RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ hotel.php?id=&lang=

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme