Laurent
Laurent

Reputation: 101

Convert Query String URL to Path

I'm trying to change http://www.mywebsite.com/en/admin/index?page=archived

to

http://www.mywebsite.com/en/admin/page/archived/

I've tried a bunch of things including:

RewriteCond %{QUERY_STRING} ^page=(.+)$    
RewriteRule ^(.*)$ http://%{HTTP_HOST}/en/admin/%1? [R=301,L]

but i have always a 404 error.

My .htaccess is into admin directory

.htaccess :

RewriteEngine On

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://%{HTTP_HOST}/en/admin/$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://%{HTTP_HOST}/en/admin/$1 [R=301,L]

# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]   

RewriteCond %{THE_REQUEST} /index\?page=(.+?) [NC]
RewriteRule ^index$ /en/admin/page/%1? [NC,L,R]
RewriteRule ^page/([^/.]+)/?$ /en/admin/index?page=$1 [NC,L]

Upvotes: 1

Views: 498

Answers (1)

Amit Verma
Amit Verma

Reputation: 41219

You can use the following code in admin/.htaccess:

RewriteEngine On
RewriteCond %{THE_REQUEST} /index\?page=([^\s]+) [NC]
RewriteRule ^ /en/admin/page/%1? [NC,L,R]
RewriteRule ^page/([^/.]+)/?$ /en/admin/index?page=$1 [NC,L]

Upvotes: 1

Related Questions