This is driving me insane - I have certain links that are re-written on a site that work perfectly fine (and I am not new to re-wring urls) but have just found that some others aren't and I cannot fathom out why.

What works:

// The link
<a href="/shop/<?php echo $parent_category['slug']; ?>/products">

// The RewriteRule
RewriteRule ^shop/([a-zA-Z0-9_-]+)/products/?$ /shop/diesel-products.php?slug=$1

What is not working:

// The link
<a href="/faqs/<?php echo $faq['slug']; ?>">

//The RewiteRule
RewriteRule ^faqs/([a-zA-Z0-9_-]+)/?$ /faqs?slug=$1

// Also tried
RewriteRule ^faqs/([a-zA-Z0-9_-]+)/?$ /faqs.php?slug=$1

What am I missing??

Just for reference (if it has any bearing) I am also using .htaccess to accept links without file extensions using:

# show file names without .php extension
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)/?$ $1.php [L,QSA]

Have you allowed execute wright for you htaccess?

Sorry, not sure what you mean?? Unless you mean RewriteEngine On in which case, yes.

However, it still doesn't make sense that some redirection is working and the other isn't

What is in $faq['slug']? By the way, why aren't you just using PHP to take care of the redirecting process? :) E.g.: redirect everything to index.php, then use $_SERVER['REQUEST_URI'] to find out what needs to be done.

E.g. www.yoursite.com/products/brand/diesel would redirect to index.php, which would then see that the URI is "products/brand/diesel", which information you could then use to PHP-include the appropriate files.

Sorry for my delays in my replies but I am not receiving notifications for some reason.

An example of the actual link would be http://www.uniteddiesel.co.uk/faqs/what-are-service-exchange-units/

So what-are-service-exchange-units is what is in $faqs['slug']

I have never redirected everything to index.php - it is not how I build and I personally don't like it (just a preference really)

I have just realised though that normally when I have an htaccess redirect that isn't working for some reason I get a page not found but for these I am getting an internal server error which is odd.

** Solved **

Now I realised it was an internal error, I checked the error logs and found the problem was a recursive internal redirect. So I lookd again at the redirect and relaised what the problem was:

I had named the main link the same as the redirect link - stupid error.

All sorted now though

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.