单页

时间:2015-12-29 09:00:12

标签: regex apache .htaccess

我想改变:

domain/link to domain/index.php?q=link

domain/notice/20151212/title-with-a to domain/index.php?q=notice&date=20151212&title=Title-with-a

使用此.htaccess文件:

RewriteEngine On
RewriteRule ^([a-zA-Z-]+)$ index.php?q=$1 [L]
RewriteRule ^notice/([0-9]+)/([A-Za-z0-9_-]+)$ index.php?q=notice&date=$1&title=$2 [L]

如果我进入domain/link or domain/link2,顺利但是如果我尝试进入domain/notice/20151212/title-with-a,我不能,因为它无法获得CSS,图像,JS文件(试图获得{{1}当文件在domain/notice/20151212/js/theme.js时,但我可以通过URL输入没有问题:

domain/js/theme.js

我做错了什么?

我在http://htaccess.mwl.be/检查此正则表达式,我认为htaccess文件是正确的。

谢谢。

1 个答案:

答案 0 :(得分:0)

尝试这样做

RewriteEngine On
RewriteRule ^notice/([^/]+)/([^/]+)/$ index.php?q=notice&date=$1&title=$2 [L]
RewriteRule ^([a-zA-Z-]+)$ index.php?q=$1 [L]

并尝试按此处恢复订单

RewriteEngine On
RewriteRule ^notice/([0-9]+)/([A-Za-z0-9_-]+)$ index.php?q=notice&date=$1&title=$2 [L]
RewriteRule ^([a-zA-Z-]+)$ index.php?q=$1 [L]

修改 在第二行末尾添加[L]并尝试我的网址,它可以正常工作

http://lab.maurosala.it/notice/a/b/

如果您不希望网址末尾的/使用此

RewriteRule ^notice/([^/]+)/([^/]+) notice.php?q=notice&date=$1&title=$2 [L]