简体   繁体   中英

Pretty URL htaccess

I have the below url that I want to prettify. Any help appreciated.

From;

http://www.example.co.uk/search-menu?r_id=1&name=testname

To

http://www.abklab.co.uk/search-menu/1/testname

I have tried below but getting Internal Server Error

# external redirect from actual URL to pretty one (WEB)
RewriteCond %{THE_REQUEST} \s/+search-menu(?:\.php)?\?r_id=([^\s&]+)&name=([^\s&]+) [NC]
RewriteRule ^ /search-menu/%1/%2? [R=302,L,NE]

# internal forward from pretty URL to actual one (WEB)
RewriteRule ^search-menu/([\w-]+)/([\w-]+)/?$ search-menu.php?r_id=$1&name=%2 [L,QSA,NC]

FYI: Below rule removes .php extension site wide;

# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=302,L]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

Try this in your htaccess :

RewriteEngine on

RewriteCond %{THE_REQUEST} /search-menu\?r_id=([^&]+)&name=([^\s]+) [NC]
RewriteRule ^ %1/%2? [NC,L,R]
RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^search-menu/([^/]+)/([^/]+)/?$ search-menu.php?r_id=$1&name=$2 [NC,L]

找到适合您的内容-该向导将帮助您使URL变得完美http://www.generateit.net/mod-rewrite/index.php

Add this line to your .htaccess file. It will take the variables and make is nice and pretty:

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)\.html$ /search-menu?r_id=$1&name=$2 [L]

Keep in mind this is basic and you will need to modify it to your addresses but it is just to give you the idea of what you need to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM