NotJay
NotJay

Reputation: 4076

How can I rewrite urls to ignore sub-directories?

I have this url:

http://www.example.com/some-annoying-folder/page.html?name=stack+overflow

But the file is actually located in the root directory and should look like this:

http://www.example.com/page.html?name=stack+overflow

Furthermore, there are similar sub-directories that need to be modified also.

As much as I use htaccess, I still am having a hard time getting used to it.

Thanks in advance for your help!

Update:

RewriteEngine On
Options +FollowSymLinks

RewriteRule .*(schedule.html|tickets.html|venue.html|city.html|concerts.html)$ $1 [L,R=302,QSA,NC]

#BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
#END WordPress

Upvotes: 0

Views: 113

Answers (2)

Ansari
Ansari

Reputation: 8218

Given additional input by OP - suppose page1.html and page2.html are two files that have non-existent directories prepended to them. This rule will fix that:

RewriteRule .*(page1.html|page2.html)$ $1 [L,R=302,QSA,NC]

If you have more such files, you can simply add them in there separated by | as above.

EDIT modified rule with more information:

RewriteRule .+/(schedule.html|tickets.html|venue.html|city.html|concerts.html)$ $1 [L,R=302,QSA,NC]

Upvotes: 1

web_bod
web_bod

Reputation: 5758

This should work with Apache:

RedirectMatch 301 ^/subfolder/$ http://www.example.com/

Upvotes: 0

Related Questions