문제

I have a rather stupid htaccess question that i would be grateful if you could help me out with.

I have an existing page on a site called contactus.php which is accessible at domain.com/contactus.php.

I want to add a redirect so you can visit domain.com/contactus which will show the contents of domain.com/contactus.php. I also want to add a 301 redirect to domain.com/contactus.php to redirect to domain.com/contactus (so whichever one you visit you see domain.com/contactus in the browser, showing content from domain.com/contactus.php).

I would have though the following code should do this, when visiting /contactus.php it's correctly 301 redirecting to /contactus but then i get an infinite redirection error. Shouldn't the 'RewriteCond' prevent the first rule being run again and hence prevent the infinite loop?

RewriteCond %{REQUEST_URI} !^/contactus$
RewriteRule ^contactus.php?$ /contactus [NC,R=301]
RewriteRule ^contactus?$ /contactus.php [NC,L]

Thanks everyone,

Dave

도움이 되었습니까?

해결책

You can use this code:

RewriteCond %{THE_REQUEST} \s/+(contact)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]

RewriteRule ^contactus/?$ /contactus.php [NC,L]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top