Mobile app version of vmapp.org
Login or Join
Kevin317

: RewriteRule for URL Subdirectory Root Have not found this in my searches on SE. I need this scenario to work: • User visits someurl.com/news/folder or someurl.com/news/somefolder/, they get redirected

@Kevin317

Posted in: #Htaccess #Redirects

Have not found this in my searches on SE.

I need this scenario to work:

• User visits someurl.com/news/folder or someurl.com/news/somefolder/, they get redirected to someurl.com/somefolder.

• If the user visits JUST someurl.com/news or /news/, they are allowed through to visit /news.

Here is my current rule: RewriteRule ^news/(.*) / [NC,R=301,L]

How do I make it allow the second bullet point? First seems to work with no issues.

Thanks all!

POST UPDATE

I have got the code

RewriteCond %{REQUEST_URI} ^news
RewriteRule ^/news news/ [NC,L]

RewriteCond %{REQUEST_URI} ^/news/(.)$ RewriteRule ^news/(.) / [NC,R=301,L]

BUT - it doesn't allow me to go to the URL something.com/news/

Any thoughts?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Kevin317

1 Comments

Sorted by latest first Latest Oldest Best

 

@BetL925

Instead of .* in your rewrite rule use .+ The star means zero or more characters, the plus means there has to be at least one.

RewriteRule ^news/(.+) / [NC,R=301,L]


Then you don't have any problems with that rewrite rule interfering with /news or /news/

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme