重定向到其他位置

时间:2016-09-08 23:45:31

标签: .htaccess

我的当前设置我的文件系统看起来像这个

/var/www/blog.example.com/v1/project.php

要访问project.php,请转到blog.example.com/project,现在我还添加了一个标题GET。

而不是去blog.example.com/project?title=This Title我希望它像blog.example.com/project/This Title

我如何完成该设置?目前.htaccess:

Options +FollowSymLinks

RewriteEngine On

RewriteRule ^project/(.*)$ v1/project.php?title=$1 [L,QSA]

RewriteCond %{REQUEST_URI} !/(v1)/ [NC]
RewriteRule ^(.*)$ %{ENV:BASE}v1/$1 [L]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]

2 个答案:

答案 0 :(得分:0)

尝试这样,

RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([\w-]+)$ v1/$1.php

RewriteCond %{REQUEST_FILENAME}.php !-f
RewriteCond %{REQUEST_FILENAME}.php !-d
RewriteRule ^project/([\w-]+)$ v1/project.php?title=$1 [QSA,L]

答案 1 :(得分:0)

有这样的话:

# turn off MultiViews to avoid conflicts
Options +FollowSymLinks -MultiViews
RewriteEngine On

# handle /project/abcd URI
RewriteRule ^project/([^/]+)/?$ v1/project.php?title=$1 [L,QSA,NC]

# add .php extension intrnally
RewriteCond %{DOCUMENT_ROOT}/v1/$1\.php -f
RewriteRule ^(.+?)/?$ v1/$1.php [L]

# forward everything to v1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?!v1/)(.*)$ v1/$1 [L,NC]