简体   繁体   English

漂亮的URL htaccess

[英]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; 仅供参考:根据以下规则,将删除整个站点范围内的.php扩展名;

# 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 : 在您的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. 将此行添加到您的.htaccess文件。 It will take the variables and make is nice and pretty: 它将使用变量并使make变得漂亮。

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. 请记住,这是基本操作,您需要将其修改为您的地址,但这只是为了让您了解您需要做什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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