Php 要重写路径吗
我有这样的文件组织-Php 要重写路径吗,php,apache,.htaccess,mod-rewrite,url-rewriting,Php,Apache,.htaccess,Mod Rewrite,Url Rewriting,我有这样的文件组织- www.mysite.com/cars/ford/ford.php www.mysite.com/cars/bmw/bmw.php 我希望用户能够访问这些页面,而无需在最后指定xyz.php文件 www.mysite.com/cars/ford www.mysite.com/cars/bmw 我如何使用重写规则让用户能够使用该格式访问页面?.htaccess RewriteRule /cars/(.*)$ /cars/$1/$1.php [L] 鉴于您更改了所有指
- www.mysite.com/cars/ford/ford.php
- www.mysite.com/cars/bmw/bmw.php
- www.mysite.com/cars/ford
- www.mysite.com/cars/bmw
我如何使用重写规则让用户能够使用该格式访问页面?.htaccess
RewriteRule /cars/(.*)$ /cars/$1/$1.php [L]
鉴于您更改了所有指向
www.mysite.com/cars/ford
表单的链接,您需要将其放入文档根目录的htaccess文件中:
RewriteEngine On
RewriteCond %{REQUEST_URI} !\.php$
RewriteRule ^/?cars/([^/])/?$ /cars/$1/$1.php [L]
这是一种常见的情况。你看过那张照片了吗?你在哪里无意中写出了规则?这比我的答案更完整、更有力@吉姆用这个。