.htaccess 使用htaccess更改URL
我在文件夹.htaccess 使用htaccess更改URL,.htaccess,.htaccess,我在文件夹public(root/public)中有一个.htaccess文件 我希望实现以下转变: /index.php->/ index.php?site=siteName->/siteName/ /siteName/或/siteName->用作?site=siteName 这是我目前为止完整的.htaccess文件(已解决案例3): 您可以使用其他规则将旧URL重定向到pretty URL和index.php删除: RewriteEngine On # external redirect
public
(root/public)中有一个.htaccess文件
我希望实现以下转变:
/index.php
->/
index.php?site=siteName
->/siteName/
/siteName/
或/siteName
->用作?site=siteName
您可以使用其他规则将旧URL重定向到pretty URL和
index.php
删除:
RewriteEngine On
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /index\.php\?current=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L,NE]
# remove index.php
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*)index\.php$ /$1 [L,R=302,NC,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9]+)/?$ index.php?current=$1 [L,QSA]
是的,一个是示例,另一个是在我的演示项目中使用的实际代码。
RewriteEngine On
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /index\.php\?current=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L,NE]
# remove index.php
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*)index\.php$ /$1 [L,R=302,NC,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9]+)/?$ index.php?current=$1 [L,QSA]