.htaccess rewrite rules stops reading url after first part of string - .htaccess

Thank you for reading.
I am trying to rewrite all dynamic category links (/product_list.php?cat_id=xxx)
to more "friendly" text links. The problem I'm running into is with subcategories:
RewriteRule Complete-AC-Systems product_list.php?cat_id=2
works great, however when a sub category is present:
RewriteRule Complete-AC-Systems__Packaged-Systems product_list.php?cat_id=7
the browser stops reading after Complete-AC-Systems and re-directs to product_list.php?cat_id=2 not cat_id=7
Most of our categories are 3 and 4 levels in, so this is a pervasive issue.
Thanks for any help you can offer.

How about reversing the order of the rules? I.e., putting the longest matches first.

Related

HTAccess Redirect using main parameter, ignore all others

firstly I know and understand how to redirect based on parameters :)
My issue is that I need to redirect all links based on the supplied MenuID parameter and ignore any other information in the query string, as not all parameters are used in each web page request, e.g. menuid=2738421; is New Products
http://www.domain.com/shop.php?menuid=2738421&menuref=Ja&menutitle=New+Products& limit=5&page=24
or,
http://www.domain.com/shop.php?menuid=2738421&menuref=Ja&menutitle=New+Products&limit=20&page=3
or,
http://www.domain.com/shop.php?menuid=2738421&menuref=Ja&page=12&limit=15
to
http://www.domain.com/new.html?page=x&limit=x
The reason for the redirection is that search-engines have indexed these pages and so I need to prettify the URLs.
Is this actually possible to create a fuzzy redirect criteria?
## 301 Redirects
# 301 Redirect 1 - works for this explicit URL, but need a partial result
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^new\.html$ http://www.monarchycatering.com/shop.php?menuid=2738421&menuref=Ja&menutitle=New+Products&limit=5&page=24 [R=301,NE,NC,L]
Any help gratefully taken, thank you in advance
Mark.
Sorry for the delay, but StackOverflow doesn't seem to have a way to flag answers that have been replied to and need my attention.
OK, if I understand you correctly, you have an incoming "reduced" semi-SEF URL out in the real world (produced by your links), such as
http://www.domain.com/new.html&limit=5&page=24
("real" SEF would be something like http://www.domain.com/new/limit/5/page/24.html)
and you need to use .htaccess to map it to real files and more Query String information:
http://www.domain.com/shop.php?menuid=2738421&menuref=Ja&menutitle=New+Products&limit=5&page=24
You want to detect new.html for example, and replace it by a fixed string shop.php?menuid=2738421&menuref=Ja&menutitle=New+Products&, using the [QSA] flag to append the existing Query String on to the end?
RewriteEngine On
RewriteRule ^new\.html /shop.php?menuid=2738421&menuref=Ja&menutitle=New+Products [QSA]
RewriteRule ^sale\.html /shop.php?menuid=32424&menuref=Ja&menutitle=Products+On+Sale [QSA]
...etc...
I believe that a & will be stuck on the end of the rewritten address if the user supplied a non-empty Query String, but be sure to test it both ways.
P.S. It probably would have been cleaner to use "comment" to reply to my question, rather than adding another answer.
It's not clear to me what your starting point is and where you're trying to end up. Do you have "pretty" URLs that you want to convert into "non-pretty" Query Strings that your scripts can actually digest?
The reason for the redirection is that search-engines have indexed
these pages and so I need to prettify the URLs.
If the search engines have already indexed the Query String non-pretty version, they'll have to now re-index with pretty URLs. Ditto for all your customers' bookmarks.
If you want to generate "pretty" links within your site, and decode them (in .htaccess) upon re-entry to non-pretty Query Strings, that should work. Your customers' existing bookmarks should even continue to work, while the search engines will replace the non-pretty with the pretty URLs.
and thanks for the interest in my question...
I have rewritten parts of my website and Google still has references to the old MenuID parameter and shop.php configuration, but now I rewriten the Query to a prettier format, e.g.
http://www.domain.com/shop.php?menuid=2738421&menuref=Ja&menutitle=New+Products&limit=5&page=24
is now
http://www.domain.com/new.html&limit=5&page=24
The pages represent product categories, and so needed to be displayed in a more meaningful manner. Customer bookmarking is not an issue, as long as I can redirect the pages.
I hope that makes sense, best wishes,
Mark.

.htaccess rewrite help request

I am hoping to gain some help with a small trouble I am experiencing with configuring a .htaccess file. Basically, I want to retrieve 2 variables from a URL String.
For example:
If someone entered www.website.com.au/folder/category/item.php
I would like the .htaccess to retrieve the last two variables (being Category and Item) and parse them to my display-item.php page.
I have a rough idea of what I need to be doing (As per below) though with all the tutes I have been reading I am a little confused.
Any help would be greatly appreciated.
:) Paul
RewriteRule /folder/(.*)/(.*).php /folder/display-item.php?category=$1&item=$2 [L]
RewriteRule ^folder/(.*)/(.*).php /folder/display-item.php?category=$1&item=$2 [L]
Works a treat. Managed to get it working.

htaccess issue, change '/' to '.'

This is my first Question to StackOverflow. I have been working with .htaccess for a PHP application that is currently in development. My Contention is changing a forward slash to a period.
I have had no Joy so far, currently my code looks like the following:
RewriteRule ^([A-Za-z_-]+)?$ app/account/?account_name=$1 [NC,L]
The above is taking away the 'app/account/?account_name=account_name' and allowing displaying the following : www.exampleurl.com/examplename. This is fine, but is there anyway to change my code so instead of /examplename it states www.exampleurl.com.examplename ? I have spent some time googling the answer to no avail.
If anyone can give me some guidance that would be fantastic, thanks in advance.
I can't think of a real replace, but what you can if the nesting is limited to some number (let's say 3) is provide multiple rules each dealing with specific nesting level:
RewriteRule ^([^/]+)/([^/]+)/(.*) /$1.$2.$3 [L,QSA]
RewriteRule ^([^/]+)/(.*) /$1.$2 [L,QSA]
# third rule is not needed, because when there is only one level, there is nothing to replace
What you need to make sure is that the rules are in descending order of the nesting levels (L flag ensures processing is stopped on a level that is matched)

301 Redirect to change structure

I have been researching redirects for a few days now and am still struggling, so I decided to post my first question here. For some reason, it is just not clicking for me.
I have redesigned and developed a client's WordPress site and need to update it's structure.
The site's current structure is:
www.domain.com/blog/postname/2011/12/26/
The new structure should be:
www.domain.com/blog/postname
I really thought this was going to be easy since all I am looking to do is drop the date, but have not been able to grasp the whole wildcard aspect and how to end what I am trying to match. Any help would be greatly appreciated. A simple answer is great, but an explanation would be even better.
I am assuming you already know how to change your WordPress permalink structure to drop the date.
To 301 redirect all of the old URLs to the new ones, add the following rules to your .htaccess file in the root of your websites domain, ahead of any existing rules that are there.
#if these 2 lines already exist, skip them and add the rest
RewriteEngine on
RewriteBase /
# if there is a request of the form /blog/post-name/yyyy/mm/dd/
RewriteCond %{REQUEST_URI} ^(/blog/[^/]+/)[0-9]{4}/[0-9]{2}/[0-9]{2}/$ [NC]
#redirect the request to the URL without the date
RewriteRule . %1 [L,R=301]
If you want to learn more about .htaccess/rewriting you can take a look at the following urls: Indepth htaccess, Brief Introduction to Rewriting, Apache Mod_rewrite.
Let me know if this works for you and/or you have any issues.

.htaccess url masking

I have a couple of wordpress urls that I want to simplify for SEO purposes. I have
http://www.example.com/fr/product-fr/review-fr/
I would like to change that to http://www.example.com/fr/product/review/ (remove -fr) but without changing the URL internally. So the user would access http://www.example.com/fr/product/review/ but the server would serve the content of http://www.example.com/fr/product-fr/review-fr/.
I want to do this to get around a URL problem with Wordpress and WPML.
Appreciate the help
Assuming the two letter lang code is always going to be constant throughout the URL:
RewriteEngine on
RewriteRule ^([A-Za-z]{2})/product/review$ /$1/product-$1/review-$1 [L,QSA]
should work a treat :)
P.S. the regexp takes any two-letter code (upper or lower case) so will work with other langs should you require.
Have you tried mod_rewrite and Rewrite rules?
Try:
^/([a-zA-Z]{2})/([^\/]+)/([^\/]+)/$ /$1/$2-$1/$3-$1
Haven't tested this though..

Resources