Htaccess 清理 url 不应该文件库

Htaccess to clearn url without should the file base

我的 htaccess 文件中有以下行需要清理 url 并且工作得很好,但我想重定向到一个页面而不显示基本文件名。

代码的作用http://example.com/index/e/dog 我想做的是隐藏 index.php 并有一个像这样的 url http://example.com/e/dog

RewriteEngine on
RewriteRule ^([^/\.]+)/?$ .php  [L,QSA] #remove php extension

RewriteCond %{THE_REQUEST} /index\.php\?e=([^\s&]+) [NC]
RewriteRule ^ /index/e/%1? [R=301,L]
RewriteRule ^index/e/([^/]+)/?$ index.php?e= [L,QSA]

不洁urlhttp://example.com/index.php?e=dog

首先,您需要确保您在应用程序中链接到 /e/dog,而不是 /index/e/dog。然后你基本上只需要从你的指令中删除 index 。也不需要附加 .php 扩展名的初始指令。

请尝试以下操作:

RewriteEngine on

# This is optional and only serves to redirect users and search engines
# that have already linked to / indexed the old URL structure.
RewriteCond %{THE_REQUEST} /index\.php\?e=([^\s&]+) [NC]
RewriteRule ^index\.php$ /e/%1? [R=302,L]

# Rewrite URL to actual filesystem path
RewriteRule ^e/([^/]+)/?$ index.php?e= [L,QSA]

仅当您确定它工作正常时,才将 302(临时)更改为 301(永久)。这是为了避免301s被浏览器缓存的问题。

测试前您需要清除浏览器缓存。