I am working on property site and I want to rewrite some of the url in my site. There are some urls which list the property type-wise. In the footer there is a list of property types such as hotels, privatevilla, apartments....etc.
Now the url of this page is property_list.php?propertytype_id=12 where 12 is the property id of apartment. Instead of this url I'd given apartments.
When user clicks on this link then the url should be sitename/apartments instead of showing property_list.php?propertytype_id=12. I've written the following code in my .htaccess file:
RewriteEngine On
RewriteRule ^([a-zA-Z]+)?$ /property_list.php?propertytype_id=$1 [NC,L]
When I click on aprtments then at that time it is showing apartments in the url and listing all apartments but the thing is it is redirecting home page and other pages also.
How do I redirect only property type related pages?
So you basically want this?
RewriteEngine On
RewriteRule ^apartments$ /property_list.php?propertytype_id=12 [NC,L]
Is this what you are looking for. So when the URL is /sitename/apartments rewrite it to /property_list.php?propertytype_id=12
RewriteEngine On
RewriteCond %{REQUEST_URI} /sitename/apartments [NC]
RewriteRule ^(.*)?$ /property_list.php?propertytype_id=12 [NC,L]
Related
My question is how to get the URL in the RewriteRule to display when I click the link (domain.com/?brandID=1&name=Beretta).
My tests make me believe it might have something to do with index.php, but maybe not. My script is triggered by the GET variable being set, and queries the DB and includes the page that displays the results (and the "ugly" url).
Here's the .htaccess code:
# Rewrite for ?brandID=1&name=Name
RewriteRule ^pistol-brand/([0-9]+)/([0-9a-zA-Z_-]+) ?brandID=$1&name=$2 [NC,L]
I want to replace domain.com/?brandID=1&name=Beretta with domain.com/pistol-brand/1/beretta
The code above displays the "ugly" url, but when I change the url to what the RewriteRule states (domain.com/pistol-brand/1/beretta), the page works.
How do I get the "new" url to display when the link is clicked?
Thanks for any assistance.
You need one more to redirect the ugly url to sef format
##1)Redirect /?brandID=foo&name=bar to //pistol-brand/foo/bar##
RewriteCond %{THE_REQUEST} /\?brandID=([^&]+)&name=([^\s&]+) [NC]
RewriteRule ^ /pistol-brand/%1/%2? [L,R]
##2)Rewrite /pistol-brand/foo/bar to /?brandID=foo&name=bar##
RewriteRule ^pistol-brand/([0-9]+)/([0-9a-zA-Z_-]+) ?brandID=$1&name=$2 [NC,L]
Currently, i have system which works through htaccess like need to hardcore url everytime a new product is added to the system, something like below
RewriteRule ^18th-and-19th-century$ sub_category.php?id=18th-and-19th-century
RewriteRule ^20th-century-furniture$ product.php?id=20th-century-furniture
RewriteRule ^pair-lacquer-cabints$ product_info.php?id=pair-lacquer-cabints
and also there are few static pages as,
RewriteRule aboutus aboutus.php?
RewriteRule contactus contactus.php?
the Idea here, what i want is to redirect the product info, category info to some index.php and access the static page as they are,
RewriteRule aboutus$ aboutus.php?
RewriteRule contactus contactus.php?
RewriteRule ^ index.php?
i tried this but everytime it takes me too the index.php page,i think there needs to some condition thing here but not able to understand how to go forward
Thanks in Advance
Try
RewriteEngine On
RewriteRule ^sub_category/([^/]*)$ /sub_category.php?id=$1 [L]
RewriteRule ^product/([^/]*)$ /product.php?id=$1 [L]
RewriteRule ^product_info/([^/]*)$ /product_info.php?id=$1 [L]
Output URLs will be
http://example.com/sub_category/18th-and-19th-century
http://example.com/product/20th-century-furniture
http://example.com/product_info/pair-lacquer-cabints
You have wrote the all url at same directory level, so there is no way you can write dynamic .htaccess rule. You need to add some identifier or some pattern in all different kind of url's which are going to access different php page.
RewriteRule ^18th-and-19th-century$ sub_category.php?id=18th-and-19th-century
RewriteRule ^20th-century-furniture$ product.php?id=20th-century-furniture
RewriteRule ^pair-lacquer-cabints$ product_info.php?id=pair-lacquer-cabints
RewriteRule aboutus aboutus.php
Like in above pages you can use url's in following style
Subcategory URL: www.domain.com/18th-and-19th-century
Product URL: www.domain.com/18th-and-19th-century/list or www.domain.com/18th-and-19th-century/20th-century-furniture
Product info: www.domain.com/18th-and-19th-century/20th-century-furniture/pair-lacquer-cabints
OR
Subcategory URL: www.domain.com/category/18th-and-19th-century
Product URL: www.domain.com/product/20th-century-furniture
Product info: www.domain.com/product_info/pair-lacquer-cabints
So accordingly you can define levels and write rewrite rules.
Similarly you can write URL for static pages
www.domain.com/content/aboutus
www.domain.com/content/contactus
or
www.domain.com/aboutus [if you don't use first level URL for subcategory like www.domain.com/18th-and-19th-century then you can use for static pages]
if this answer is helpful to you then i will write .htaccess rules
I'm changing a site layout from example.com/product.php?id=1 to example.com/new.php
I need to leave a rule for 301 redirect for this redirection from id=1 to new.php.
What I have, that WORKS currently
RewriteCond %{query_string} id=1
RewriteRule (.*) https://example.com/new.php? [R=301,L]
Problem Needs Solving:
There is also a page called example.com/other-products.php?id=1
All the products on this OTHER page are ALSO being redirected to 'new.php'.
Final Question:
How can I apply specificity to this redirect such that only dynamic urls that are preceded by products.php are redirected and all other dynamic urls on the site with identical id number (e.g. id=1) stay put?
Thanks!
You need to use correct URI pattern in RewriteRule:
RewriteCond %{query_string} ^id=1$ [NC]
RewriteRule ^product\.php$ https://example.com/new.php? [R=301,L,NC]
Take note of RewriteRule ^product\.php$, which will only affect /product.php?id=1 URL but won't affect /product-abc.php?id=1 OR /product.php?id=123
I have a website and trying to rewrite it’s url. The pages are as:
www.mydomain.com/newv2/pvgs.php?archive=april/2014
www.mydomain.com/newv2/pvgs.php?archive=april/2014&page=1
I have using pagination but I want when any one click on for archive months then he will get only 1 URL as http://www.mydomain.com/newv2/april/2014
And when he click on pagination the page nuber added at last means 2nd url
as http://www.mydomain.com/newv2/april/2014/1.
Place this in /newv2/.htaccess:
RewriteEngine On
RewriteBase /newv2/
RewriteRule ^([a-z]+/[0-9]+)/?$ pvgs.php?archive=$1 [L,QSA]
RewriteRule ^([a-z]+/[0-9]+)/([0-9]+)/?$ pvgs.php?archive=$1&page=$2 [L,QSA]
I have viewed similar questions to mine, but it does not pertain to my specific example.
1st URL (what is to be sent to the server and is originally inputted to the URL bar): www.site.com/?variable1=3&variable2=filename.php
2nd URL (what is shown to the user in the URL bar): www.site.com/filename.php
where "filename.php" is the same value as "variable2" in the original URL.
I have seen examples of the opposite, where someone enters the 2nd URL and it replaces it with the 1st URL, but that's not what I want.
Currently what I have:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^/([A-Za-z0-9]+)$ /?CommID=$1&FileName=$2 [NC,L]
which I got the structure from the link provided from this question, but that's not working.
I'm not trying to redirect, just mask the current URL so it is SEO friendly. I need to grab both variables from the URL to have the dynamic content be pulled correctly.
Any ideas?
Try adding the following to your .htaccess file in the root of your domain
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
#if the query string has a commid and a fIlename Param
RewriteCond %{QUERY_STRING} ^CommID=([^&]+)&FileName=([^&]+) [NC]
#redirect users to the Pretty URL of www.site.com/variable1/filename.php
RewriteRule .* /%1/%2? [L,R=301]
#for a URL like this in address bar www.site.com/variable1/filename.php
#CommID will contain variable1 and FileName will contain filename.php
RewriteRule ^([A-Za-z0-9]+)/([A-Za-z0-9\.]+)$ /?CommID=$1&FileName=$2 [NC,L]
Edit:
Also redirect users using the query string URL to the pretty URL