0

I'm new to htaccess and I need some help with a rewrite rule.

I wish to rewrite:

/all-accomodation/anything/ to: /portfolio-gallery/anything/ 

The 'anything' could be any slug.

One thing to note is that I have a page with a slug of 'all-accomodation' and when requested by itself shouldn't rewrite.

Here is my current htaccess file:

# 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 

Thanks in advance,

Dave

1 Answer 1

2

You don't want to edit Wordpress's rewrite. Above that block, you can try:

<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^all-accomodation/(.+)(/?) /portfolio-gallery/$1$2 [L] </IfModule> 

This will 301 redirect all requests.

Sign up to request clarification or add additional context in comments.

5 Comments

Great, thanks Rob. Is there anyway I can have it just rewrite, i.e no 301? I want to keep the URL as /all-accomodation/cottages/ but serve the page: /portfolio-gallery/cottages/
Also, just a note here, this assumes that THAT path is not a real directory path (!-d part)
If I leave the 301 in (to test), it 301's /all-accomodation to /portfolio-gallery. /all-accomodation/cottages redirects to /portfolio-gallery/cottages as expected, but if I take out the 301, /all-accomodation/cottages 404's
Thanks for your help so far Rob, still getting a 404, could it be because wordpress is also rewriting to index.php?
Yes it was wordpress rules, have sorted, thanks again for your help +1 and marked as answer ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.