简体   繁体   中英

Is it possible to redirect traffic from page that doesn't exist to existing page with .htaccess?

The issue I am trying to solve is that I have a folder with a name that has funny capitalizations, eg TeStPage. I would like all requests to my domain, in all versions of caps, redirect to that page.

I tried a simple:

Redirect /testpage http://www.mydomain.com/TeStPage

But that crashed my site, because it said 'Non-URL'.

How do I do .htaccess re-direct to handle all capitalization cases to be redirected to my /TeStPage url?

I searched Apache's documentation for the syntax and rules of .htaccess, but couldn't find a lot of details. Can someone point me to a good tutorial/reference file I can use to learn more about .htaccess commands in depth?

Thanks.

Try this mod_rewrite rule:

RewriteEngine on
RewriteCond $0 !=TeStPage
RewriteRule ^testpage$ /TeStPage [NC,R=301,L]

Did you check the mod_rewrite spec at http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html ?

Take for instance the typical Wordpress URL rewrite, which redirects all requests that point to a non existing file/folder to index.php, passing in the original request URL:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase / 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

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