我需要帮助处理我的Htaccess密码。
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule (.*)\.php$ $1 [R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L,QSA]我的目录结构是:
Public_Html
css/style.css
img/icon.png
/2/user.php
index.php
create.php现在,上面的htaccess代码正在从URL中删除.php扩展。
示例
-> example.com/index.php -> example.com/index
-> example.com/2/user.php -> example.com/2/user此Htaccess文件的问题
example.com///*/// -> example.com示例: example.com/create.php -> example.com/create/
/create without /,那么应该自动添加它。
示例: example.com/create -> example.com/create/换句话说,如果在移除.php之后,这两者都是相同的
**Example:** example.com/create = example.com/create/example.com/2 -> example.com/2/
这里2是一个文件夹。我对这个htaccess脚本有一些问题。我在Google和Stack溢出上搜索了很多,但仍然找不到任何解决方案。
*这不是一个重复的问题。在标记为副本之前,请仔细检查它。如果你能帮我,我会很高兴的。
发布于 2017-08-21 14:28:03
这是你需要的一切,所有的问题都是用代码、信息和例子回答的!为每个操作提供1×1的步骤,然后提供整个代码!
1-)解析.php扩展
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]如果你去了example.com/user.php,example.com/user就可以工作了
2)将不存在的错误链接重定向到example.com
如果用户键入不存在的链接,例如example.com///*,用户将被自动重定向到example.com
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>(3)将 example.com/index.php 或 example.com/index 重定向到 example.com
RewriteCond %{THE_REQUEST} /index(\.php)?[/?\s] [NC]
RewriteRule ^(.*?)index(?:\.php)?$ /$1 [L,R=301,NC,NE]如果不是4-)删除尾随斜杠,否则添加
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [R=301,L]如果在普通文件之后添加了一个尾随斜杠,这将删除它。如果它是一个目录,并且有,它将保持不变。如果没有,则会自动添加一个拖尾斜杠。
您将能够访问目录!
( 5-)从.php中删除.php (重定向到没有.php的文件名)
RewriteCond %{THE_REQUEST} \.(php|cfm)[\s?] [NC]
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)\.(cfm|php)$ /$1 [R=301,L,NE]将整个代码合并为 .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [R=301,L]
RewriteCond %{THE_REQUEST} /index(\.php)?[/?\s] [NC]
RewriteRule ^(.*?)index(?:\.php)?$ /$1 [L,R=301,NC,NE]
RewriteCond %{THE_REQUEST} \.(php|cfm)[\s?] [NC]
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)\.(cfm|php)$ /$1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>我希望这对你有帮助。
很乐意帮忙,享受吧!
https://stackoverflow.com/questions/45796597
复制相似问题