简体   繁体   中英

How do I write a rewrite rule to htaccess?

I need to redirect any www.mysite.com/anything/anything OR www.mysite.com/anything AND EXCLUDE www.mysite.com/app

TO www.mysite.com/app

Of course I want to exclude is optional. It would just be an extra redirect which would take extra time I suppose, it would be nice to have it excluded though.

I found these basic examples http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html and have done this:

RewriteRule ^*/*/$ /app
RewriteRule ^*/$ /app

but it doesn't work plus I still don't know how to exclude /app

Help please?

I think.* stands for 0 or more dots in regular expressions, my examples are completely wrong, I need anything syntax instead of the dot you used in your answers.

You could try this:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/app$ 
RewriteRule ^.*$ /app [L]

Does this work for you?

RewriteEngine on
RewriteRule ^.*$ app/ [L]

Unfortunately it doesn't exclude the right path. But try it first.

Put this code in your .htaccess under DOCUMENT_ROOT:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^(?!app/).*$ app [L,NC]

Negative lookahead in above RewriteRule will redirect everything except a URI that starts with /app/ to /app .

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