简体   繁体   English

htaccess将url文件夹/文件重写为folder / file.php

[英]htaccess rewrite url folder/file to folder/file.php

I want ajax/file address to be redirected to ajax/file.php using .htaccess. 我想使用.htaccess将ajax/file地址重定向到ajax/file.php I created a .htaccess file like below but that gives a 500 Internal Server Error. 我创建了一个.htaccess文件,如下所示,但给出了500 Internal Server Error。

RewriteEngine On
RewriteRule ^ajax/(.*)$ ajax/$1.php [L]

An additional information is that my website is working under a sub-folder. 其他信息是我的网站在子文件夹下工作。 (localhost/myproject) RewriteRule ^ajax/(.*)$ /ajax/$1.php [L] redirects url to (localhost/ajax/file.php) instead of (localhost/myproject/ajax/file.php (localhost / myproject) RewriteRule ^ajax/(.*)$ /ajax/$1.php [L]将url重定向到(localhost / ajax / file.php)而不是(localhost / myproject / ajax / file.php)

Problem is that .* in your regex also matches file.php . 问题是您的正则表达式中的.*也与file.php匹配。

Use your rule like this: 像这样使用您的规则:

Options -MultiViews
RewriteEngine On

RewriteRule ^ajax/([^./]+)/?$ ajax/$1.php [L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM