I am working in a catalog store, so far i solved the url rewrite for the main page of the store (store.php) and the categories pages (category.php), this is what i got so far:
RewriteCond %{THE_REQUEST} /category-store\.php\?catid=([a-zA-Z0-9_-]+) [NC]
RewriteRule ^/store/%1? [R=302,L,NE]
RewriteRule ^store/([a-zA-Z0-9_-]+)/?$ category.php?catid=$1 [QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
So the store page is
www.example.com/store
And a category page is
www.example.com/store/furniture
I try to break the products page i want it turn this:
www.example.com/product.php?id=1
into
www.example.com/store/wood-chair-1
This is what i got that doesn't work...
RewriteRule ^store/(.*)-([0-9]+)$ product.php?id=$2 [QSA]
(.*) as product title - ([0-9]+) as product id
This is link example in php:
'. $row['prod_title'] . '
Related
I have return the below htaccess rule for actual URL http://apis.jaspee.com/services/srvcRest.php?rqst=getCMS
RewriteRule ^(.*)$ services/srvcRest.php?rqst=$1 [QSA,NC]
but it works as
http://apis.jaspee.com/services/srvcRest.php?rqst=services/getCMS
because of that the page is redirected to page not found page. $1 fetch the value as services/getCMS but I want the $1 should fetch the value as getCMS only.
If its going in root /.htaccess, try:
RewriteCond %{REQUEST_URI} !^.*/srvcRest\.php$ [NC]
RewriteRule ^services/(.*)$ services/srvcRest.php?rqst=$1 [QSA,NC]
If its going in /services/.htaccess, try:
RewriteCond %{REQUEST_URI} !^.*/srvcRest\.php$ [NC]
RewriteRule ^(.*)$ srvcRest.php?rqst=$1 [QSA,NC]
Becouse in google webmasters I have 550.000 not found pages - 404 - I want to make some redirections to the search page.
To be userfoul for the users, need to go to the search page, but is realy complicated for me, becouse I need to EXTRACT the search phrase from the 404 url:
Here are the 2 type of url with 404 errors, and need to be redirected.
DOMAIN/movie/12298295-Iron-Man-3
DOMAIN/serie/15108-The-Walking-Dead/seasons/3/episodes/10
Of corse, I need to extract JUST THE NAME of the movie, or the serie and redirect to this url
DOMAIN/search?q=Iron-Man-3
DOMAIN/search?q=The-Walking-Dead
Well this is the URL by parts:
For "movies" just have 4 parts:
DOMAIN - of corse, is the domain name of the website
/movie/ - is created based on the content type (movie or serie)
12298295- is the ID for this item and can be form - 1 - to
infinite
Iron-Man-3 - the name of the movie (is wath I want to get)
For "series" - THE SAME like for the movies, but at the end can have more parts, and the full URL can be: (all this url, for an normal page with NO 404, are ok)
DOMAIN/serie/15108-The-Walking-Dead/seasons/3/episodes/10 - Link to episode page
DOMAIN/serie/15108-The-Walking-Dead/seasons/3/ - Link to some season page
DOMAIN/serie/15108-The-Walking-Dead/ - Link to the TOP page for this serie
Please note, I need to redirect this url, JUST if the result is an 404 page (ErrorDocument 404), becouse the same type of url are used in all pages.
Here is my actual .htacces
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php[^/] /$1? [L,R=301,NC,NE]
RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteRule ^(.*?)index\.php(?:/(.*))?$ /$1$2? [L,R=301,NC,NE]
RewriteCond %{QUERY_STRING} ^q= [NC]
RewriteRule ^busqueda\b /busquedas [R=301,L,QSA]
# Redirect Trailing Slashes...
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Many thanks for your help
The following shall work for both movies and series:
RewriteRule ^(?:movie|serie)/\d+-([^/]+) /search?q=$1 [R=301,L,NC]
Most of the RewriteRules are working fine but there are a couple that have the same word in them and aren't going to the correct page.
Here is my full htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
# Rewrites for main pages
RewriteRule home index.php
RewriteRule about-us about-us.php
RewriteRule business-advice business-advice.php
RewriteRule associates associates.php
RewriteRule become-an-associate associates-sign-up.php
RewriteRule blog blog.php
RewriteRule contact-us contact-us.php
RewriteRule log-in log-in.php
RewriteRule sign-up sign-up.php
The problem resides within the two associated links. When I go to [MYURL]/associates it works fine but if I go to [MYURL]/become-an-associate it takes me to the correct URL but shows content from [MYURL]/associates
Anybody got any ideas?
Thanks,
The pattern for RewriteRule's are regular expressions and the rules all loop until the URI stops changing. That means the first time around, when you request /become-an-associate, it matches and is rewritten to /associates-sign-up.php. Then, the second time around, the rule with the pattern associates matches because of "/associates-sign-up.php". You need to add boundary checks (e.g. ^ and $) as well as the [L] flag:
# Rewrites for main pages
RewriteRule ^home/?$ index.php [L]
RewriteRule ^about-us/?$ about-us.php [L]
RewriteRule ^business-advice/?$ business-advice.php [L]
RewriteRule ^associates/?$ associates.php [L]
RewriteRule ^become-an-associate/?$ associates-sign-up.php [L]
RewriteRule ^blog/?$ blog.php [L]
RewriteRule ^contact-us/?$ contact-us.php [L]
RewriteRule ^log-in/?$ log-in.php [L]
RewriteRule ^sign-up/?$ sign-up.php [L]
i am trying to create an .htaccess file that will achieve the following
create a clean url like this www.mydomain.com/About-Us with page page.php?title=About Us
query a database with the parameters passed on the url like this www.mydomain.com/?search=abc and it pulls to page index.php?search=abc
this is my code so far
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^?search=([0-9]*)$ index.php?id=$1 ## e.g www.mydomain.com/?search=try
RewriteRule ^([A-Z]*)$ page.php?name=$1
## www.mydomain.com/About-Us
##ErrorDocument 404 PageNotavailabale
####Protect the system from machines with worms
RewriteRule (cmd|root)\.exe - [F,E=dontlog:1]
#### To hold and redirect css/images/js files
RewriteRule images/(.+)?$ images/$1 [NC,L]
RewriteRule css/(.+)?$ css/$1 [NC,L]
RewriteRule js/(.+)?$ js/$1 [NC,L]
Why not using this kind of url for your search engine : www.domain.com/search/abc ?
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^search/([a-zA-Z0-9]+)$ index.php?search=$1
RewriteRule ^([a-zA-Z0-9]+)$ index.php?page=$1
Then, your access your pages with www.domain.com/<myPage>.
And your search engine with www.domain.com/search/<mySearch>
EDIT :
Please notice your rules doesn't allow a lot of params :
^?search=([0-9]*)$ allows only numbers (even an empty parameter)
^([A-Z]*)$ allows only uppercase letters (and also empty parameter)
I need help with htaccess URL rewriting for my site.
Problem is that just first page in some category has nice cruft free URL, and all other pages has dirty URLs.
For example first page has link like this:
http://www.my-site-name.com/Category-name/Subcategory-name/
But page 2, and any other pages are like this:
http://www.my-site-name.com/showcat.php?cat=Category-name&subcat=Subcategory-name&page=2
http://www.my-site-name.com/showcat.php?cat=Category-name&subcat=Subcategory-name&page=3
So, I need some SEO friendly htaccess redirect rule to make URLs like this:
http://www.my-site-name.com/Category-name/Subcategory-name-page-X/
or like this
http://www.my-site-name.com/Category-name/Subcategory-name/X/
But probably I would like first more.
This is part of .htaccess for that: (I just added full content, maybe there is something more about it.
## For top rated items
RewriteRule ^top/page/(.*)/$ top.php?page=$1 [L]
## For latest items
RewriteRule ^latest/recent-page-(.*)/$ latest.php?page=$1 [L]
## For show most rated - most clicked - most downloaded and most searched items
RewriteRule ^most-rated.html$ showmost.php?type=1 [L]
RewriteRule ^most-clicked.html$ showmost.php?type=2 [L]
RewriteRule ^most-downloaded.html$ showmost.php?type=3 [L]
RewriteRule ^most-Searched.html$ showmost.php?type=4 [L]
## For showing category of item
RewriteRule ^(.*)/$ showcat.php?cat=$1 [L]
## For showing subcategory of item
RewriteRule ^(.*)/(.*)/$ showcat.php?cat=$1&subcat=$2 [L]
## For showig item
RewriteRule ^(.*)/(.*)/(.*).html$ show.php?cat=$1&sub_cat=$2&img=$3&rewrite=true [L]
## this section should be inserted just after the showing item rule above
#if the query string has cat, sub_cat and Img
RewriteCond %{QUERY_STRING} ^cat=(.+)&sub_cat=(.+)&img=(.+)$ [NC]
#and it is for resource show.php, then 301 redirect to Keyword rich URL
RewriteRule ^show\.php$ http://www.my-site-name.com/%1/%2/%3.html? [NC,L,R=301]
I also cleaned it up a little
#don't rewrite if file or dir exists
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [L]
## For showing category of item
RewriteRule ^([^/]*)/$ showcat.php?cat=$1 [L]
## For showing paged subcategory of item
RewriteRule ^([^/]*)/([^/]*)-page-([0-9]+)/$ showcat.php?cat=$1&subcat=$2&page=$3 [L]
## For showing subcategory of item
RewriteRule ^([^/]*)/([^/]*)/$ showcat.php?cat=$1&subcat=$2&page=1 [L]
## For showig item
RewriteRule ^([^/]*)/([^/]*)/([^/]*).html$ show.php?cat=$1&sub_cat=$2&img=$3&rewrite=true [L]