网址重写和修剪网址

时间:2014-09-10 18:33:41

标签: .htaccess url-rewriting

我需要你的宝贵帮助。

我有一个网址:

http://domain.com/v/12345

我的ht访问设置为将12345传递给php脚本,如:

htaccess:

RewriteRule  ^v/([a-zA-Z0-9_-]+)$  /script.php?v=$1 [L]

脚本php:

http://domain.com/script.php?code=12345

完美地工作但是..但是有一个但是,我会写我的网址:

http://domain.com/12345/my-dog-is-very-fat

你可以帮我改变我的htaccess吗?因为如果我使用/ my-dog-is-fat或只是/我得到404错误。

我试着更好地解释一下:

我会在网址中分享与seo关键字的链接,例如

mydomain.com/alphanumericCode/thi-is-my-dog-article

其中alphanumericCode是myscript.php的获取?V =

这是我的htaccess:

RewriteEngine On
RewriteRule ^view/([a-zA-Z0-9_-]+)$ /view.php?v=$1
RewriteRule ^folder/([a-zA-Z0-9_-]+)$ /filefolderlist.php?f=$1
RewriteRule  ^home$            /index.php [L]
RewriteRule  ^report$          /report.php [L]
RewriteRule  ^play/([a-zA-Z0-9_-]+)$               /play.php?v=$1 [L]

###Added by anubhava
RewriteRule ^v/([\w-]+)/?$ /script.php?v=$1 [L,QSA]
RewriteRule ^([0-9a-z]+)/.+$ /script.php?v=$1 [L,QSA,NC]
##end

RewriteRule  ^privacy-policy$          /privacy.php [L]
ErrorDocument 404 404.php 

1 个答案:

答案 0 :(得分:0)

您可以为新URI方案设置新规则:

RewriteEngine On

RewriteRule ^v/([\w-]+)/?$ /script.php?v=$1 [L,QSA]

RewriteRule ^([0-9a-z]+)/.+$ /script.php?v=$1 [L,QSA,NC]