简体   繁体   English

htaccess重写到错误的页面

[英]htaccess rewriting to wrong page

I have begun learning htaccess and i'm massively struggling. 我已经开始学习htaccess了,我在努力挣扎。 I'm simply trying to remove my .php from a URL 我只是想从网址中删除.php

subdomain.example.com/weddings.php subdomain.example.com/weddings.php

to

subdomain.example.com/weddings/ subdomain.example.com/weddings/

to be honest that's not entirely it. 老实说,这不完全是。 the full url is 完整网址是

subdomain.example.com/weddings.php?section=pyromusicals#divname subdomain.example.com/weddings.php?section=pyromusicals#divname

which im trying to make into 我试图把它变成

subdomain.example.com/weddings/divname subdomain.example.com/weddings/divname

for now though just the removal of the .php to / would be helpful. 目前,尽管将.php删除到/会有所帮助。

so far I have in my htaccess file 到目前为止,我的htaccess文件中已有

 RewriteEngine  on
 RewriteCond %{REQUEST_URI} ^/(.*).php$
  RewriteRule ^(.*)$ %1 [L,QSA]

which is re-writing to 这是重写到

subdomain.example.co.uk/wedding-fireworks/ subdomain.example.co.uk/wedding-fireworks/

which is great but it also generates a 404 error page not found. 很好,但它还会生成未找到的404错误页面。

The requested URL /wedding-fireworks/index was not found on this server. 在此服务器上找不到请求的URL / wedding-fireworks / index。

Is this what you are wanting to do? 这就是你想做的吗?

RewriteRule ^([^/]+)/([^/]+) /$1.php?section=pyromusicals#$2 [QSA,L]     
RewriteRule ^([^/]+) /$1.php [QSA,L]

Note that is assuming your section will always = pyromusicals 请注意,假设您的section将始终= pyromusicals

If section changes, you will need to include it in your URL also example below. 如果部分更改,则需要将其包括在下面的URL示例中。

http://www.yoursite.com/somephppage/nameofsection/divname

Then your mod rewrite would look like this. 然后,您的mod重写将如下所示。

RewriteRule ^([^/]+)/([^/]+)/([^/]+) /$1.php?section=$2#$3 [QSA,L]     
RewriteRule ^([^/]+) /$1.php [QSA,L]

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

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