I've a link goes to a file with GET parameters.
Link in href="" is:
http://www.aaa.com/part1/part2/part3/
My htaccess is
RewriteRule ^(.*)/(.*)/(.*)/ detail.php?part1=$1&part2=$2&part3=$3 [L]
With this I get 3 data and show the URL as:
http://www.aaa.com/part1/part2/part3/
So far all works well. But i would like to change the URL but still get the GET values
The final result of URL should be:
http://www.aaa.com/part1-part2-text
I want to remove the / after part1 and part2 and remove part3 completly and put a text instead of part3.
I can rewrite the URL with:
RewriteRule ^(.*)/(.*)/(.*)/ part1=$1-part2=$2-text
but with this i'm not able to get the GET parameters.
Is there a way to combine these to rewrite parameters?
Thanks
You should read the mod_rewrite module first.
RewriteRule ^(.*)-(.*)-text$ detail.php?part1=$1&part2=$2
Related
I am trying to have a URL like the following:
http://example.com/product/category/name?ref=title
Where there is a URL Rewrite AND (at least 1) ?attribute=value at the end of the URL.
How do I get the value of that attribute with the '?' before it? I have tried just using the basic $_GET[''] to get the value, but it doesn't seem to work.
Here are a few ideas:
RewriteRule /page /index.php?attr=val [QSA]
You can also use %{QUERY_STRING} variable in the rewrite rule.
I'm having e commerce website in php. And now moving to fancy urls, url rewriting.
for that i've variable length of parameters with optional variables too.
for example,
http://example.com/product.php?page=e&id=23&color=blue&size=xxl&width=200&height=100
Here, the parameters are optional That means, some variables may or may not participage in the url except id.
here, page=e is fixed and it is not dynamic. ( the reason behind is i've other rewritten rules like ^categories, ^toys etc..
and re-written url should be one of these,
http://example.com/e/23/color-blue/size-xxl/
http://example.com/e/26/color-black/width-500/height-900/
http://example.com/e/56/type-shirt/color-white/height-345/size-xl/
i've tried below with no luck,
RewriteRule ^e/([^/.]+)/?$ product.php?page=e&url=$1 [L,NC,QSA]
i'm getting all $_GET values like this,
http://example.com/product.php?page=e&id=23&color=blue&size=xxl&width=200&height=100
but i'm trying to achieve like this,
http://example.com/e/23/color-blue/size-xxl/width-200/height-100
how can i pass the queries with slashes and not &'s.
that main idea behind above last url is to process the whole fancy url into simple one in php,
and then use those variables in the page script. is there any better solution than this ??
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^(e)/([0-9]+)/([^-]+)-([^/]*)(/.*)?$ product.php$5?page=$1&id=$2&$3=$4 [L,QSA]
RewriteRule ^(product\.php)/([^-]+)-([^/]*)(/.*)?$ $1$4?$2=$3 [L,QSA]
How to hide parameters (query_string) in URL but send them to page hidden, not visible in address bar
example:
I have this:
http://localhost/project/company/redeem/category/Shirts/18?category_id=18
I want:
http://localhost/project/company/redeem/category/Shirts.html
But I want to get sent parameter in PHP $_GET['sent']
I tried to redirect to page with no parameters(no query_string) [R] and after that give page some parameters (silently) without [R] redirection (without changing address itself)
I tried to use RewriteRule in .htaccess with different flags and different ways but nothing worked
Please suggest.
As far as i am aware you can only hide the parameter key (in this case 'category_id') using the RewriteEngine:
RewriteEngine On
Then use a RewriteRule like this
RewriteRule ^project/company/redeem/category/Shirts/18/(regex of whatever you expect for your parameter)$ project/company/redeem/category/Shirts/18.php?category_id=$1
Not sure if the first 18 is coincidence or always the same as the category_id value. If it is you can also use
RewriteRule ^project/company/redeem/category/Shirts/(regex of whatever you expect for your parameter)$ project/company/redeem/category/Shirts.php?category_id=$1
If you want to use $_GET the parameters have to be written to the url somewhere. You can only try to hide it.
For example if you know each category by a name you could put those into the url instead of numbers. Lets say category_id 18 is "V-Neck Unisex-Shirts" you could use a url like
http://localhost/project/company/redeem/category/Shirts/V-Uni
and tell your script to use category "V-Uni" instead of "18".
.htaccess:
RewriteRule ^project/company/redeem/category/Shirts/([a-zA-Z-]*)$ project/company/redeem/category/Shirts.php?category=$1
For example i have
3 php pages
www.example.com/page1.php?var1=data1&var2=data2&var3=data3
www.example.com/page2.php?var1=data1&var2=data2&var3=data3
www.example.com/page3.php?var1=data1&var2=data2&var3=data3
For good SEO . I need URL like
www.example.com/page1/data1-data2-data3
www.example.com/page2/data1-data2-data3
www.example.com/page3/data1-data2-data3
I got something URL rewriting with PHP but am confused how to implement it for multiple dynamic PHP pages.
i need all the variables for proper functioning of php pages
Put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteRule ^(page1|page2|page3)/([^-]+)-([^-]+)-([^-/]+)/?$ /$1.php?var1=$1&var2=$2&var3=$3 [L,QSA,NE]
In your .htaccess you should add the line:
RewriteRule ^(\w+)/(\w+)-(\w+)-(\w+)$ /$1.php?var1=$2&var2=$3&var3=$4 [QSA]
The first part captures the page name (script name, in your case), then each successive query string parameter. The QSA key tells the redirect to take any additional query string parameters not specified explicitly along with the request.
This is my URL rewrite:
RewriteRule ^cars/$ cars.php
RewriteRule ^cars/([a-z-]+)/$ /cars.php?model=$1
This works, so my URL is like this:
example.com/cars/porche/
refers to
cars.php?model=porche
Now Im making more search criterias, so I want to be able to add for example model year, car manufactor, etc. like this:
example.com/cars/porche/?model_year=xxx&car_manufactor=xxx
Right now this does not work with the current rewrite, but I can't figure out why.
Simple, just add QSA:
RewriteRule ^cars/([a-z-]+)/$ /cars.php?model=$1 [QSA]
That tells the rewrite engine to append any other query parameters to the rewritten URL as well.