vegas
vegas

Reputation: 111

pretty url with folder name and two variables

ugly url - example.com/folder_name/art.php?id=9&s=something
want to be - example.com/folder_name/id/s

here is my try

# external
RewriteCond %{THE_REQUEST} \s/+art\.php\?id=([^&]*)&s=([^\s&]*) [NC]
RewriteRule ^ /%1/%2? [R=301,L]

# internal
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/?$ art.php?id=$1&s=$2  [L]  

doesn't work
entering ugly url - address bar is unchanged
entering pretty url - getting error 404

pls help

Upvotes: 1

Views: 41

Answers (1)

anubhava
anubhava

Reputation: 785246

You rules will have to allow folder_name as well so use:

RewriteEngine On

# external
RewriteCond %{THE_REQUEST} \s/+(folder_name)/art\.php\?id=([^&]*)&s=([^\s&]*) [NC]
RewriteRule ^ /%1/%2/%3? [R=301,L]

# internal
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(folder_name)/([\w-]+)/([\w-]+)/?$ $1/art.php?id=$2&s=$3 [L,QSA,NC]  

This assumes there is no other .htaccess in folder_name/.

In case there is a .htaccess inside that subfolder then use this .htaccess:

RewriteEngine On
RewriteBase /folder_name/

# external
RewriteCond %{THE_REQUEST} /art\.php\?id=([^&]*)&s=([^\s&]*) [NC]
RewriteRule ^ %1/%2? [R=301,L]

# internal
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/([\w-]+)/?$ art.php?id=$1&s=$1 [L,QSA]

Upvotes: 2

Related Questions