.htaccess文件夹帮助


.htaccess help for folders?

我正在尝试用htaccess制作漂亮的url ..我想让url www.mysite.com/movie/name.html来自www.mysite.com/movie/movie.php?url=name

这里movie/是一个文件夹,类似地,我还有两个文件夹像albums/和news/,我想让url在

下面
  • www.mysite.com/albums/name.html from ww.mysite.com/albums/album.php?id=name

  • www.mysite.com/news/name.html from ww.mysite.com/news/album.php?id=name

.htaccess在

<IfModule mod_rewrite.c>
# removing .php extension 
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}'.php -f 
RewriteRule ^(.*)$ $1.php
#Code to rewrite www.mysite.com/movie/name to www.mysite.com/movie/movie.php?url=name
RewriteEngine On
RewriteRule ^(.+)/([a-zA-Z0-9_-]+)$ movie.php?url=$1
</IfModule>

但是我让每个页面重定向

请建议正确的代码

try this

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}'.php -f 
RewriteRule ^ - [S=3,L]
#www.mysite.com/movie/movie.php?url=name
RewriteRule ^movie/([^/]+)'.html?(.*)$ movie/movie.php?url=$1$2 [QSA,S=2,L]
#www.mysite.com/news/album.php?id=name
RewriteRule ^news/([^/]+)'.html?(.*)$ news/album.php?id=$1$2 [QSA,S=1,L]
#www.mysite.com/albums/album.php?id=name
RewriteRule ^([^/]+)/([^/]+)'.html?(.*)$ $1/$2.php?id=$2$3 [QSA,L]

重定向PHP文件使用:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/])/$ /$1.php [L]

特定页面:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/])/([0-9]+)/([^/])'.html$ /$1.php?url=$2 [L,QSA]

你可以在这里查看Documentation