简体   繁体   中英

htaccess redirect rules for file extensions

I have searched SO and tried different things but none seem to work:

I want all these URLs to go to one page only:

http://myurl.com/apply
http://myurl.com/apply/
http://myurl.com/apply.html
http://myurl.com/apply.php

Should all go to this page here ( http://myurl.com/apply.php ) but the URL should look like this:

http://myurl.com/apply

Right now I only have the part where it redirects to the .php page. I cannot get the URL masking to work where the .php is hidden

Redirect /apply http://prosaverapp.com/apply.php
Redirect /apply/ http://prosaverapp.com/apply.php
Redirect /apply.html http://prosaverapp.com/apply.php
Redirect /apply.php/ http://prosaverapp.com/apply.php

Here are an example.

If you only want to remove the extensions:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]

Some useful how to's from Apache: https://httpd.apache.org/docs/current/howto/htaccess.html

You can use these rules in your site root .htaccess:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d    
RewriteCond %{THE_REQUEST} \s/+(\S+?)(?:/|\.(?:html|php))[\s?] [NC]
RewriteRule ^ /%1 [R=301,NE,L]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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