.htaccess cant pass variables to rewrited page on WAMP - php

I was coding few php pages to display customer quotations, on rep.php, user can click view details button (POST quoteID as the variable to quotedetails.php?quoteID=Q123456) to view the detailed info about a particular quote.
Then I use .htaccess to make all php pages to html extention and rewrited url from 'quotedetails.php?quoteID=Q123456' to 'quotedetails/Q123456.html', everything works fine on XAMPP, but under WAMP, rewrited url does not display the data on that quotedetail page, i tested by using old url (quotedetails.php?quoteID=Q123456), it works fine, so I guess it must be something wrong with my .htaccess rules as the new html url cannot pass the variable (quoteID).
this is my .htaccess file:
Options +FollowSymlinks
RewriteEngine on
#sideBar.php edit rep link with the styles below, e.g. all,all.html (showing all)
#or reps/$repID,$repName.html
RewriteRule ^reps/all,all.html$ rep.php?repID=all&repName=all [QSA]
RewriteRule ^reps/([A-Z]+),([A-Za-z\sA-Za-z]+).html$ rep.php?repID=$1&repName=$2 [QSA]
RewriteRule ^reps/([A-Z]+).html$ rep.php?repID=$1 [QSA]
#rep.php including page string, edit pager links in rep.php with following styles,
#\s indicating a white space therefore mod_rewrite can recognise the repName
#e.g. reps/$repID,$repName,$page.html
RewriteRule ^reps/([A-Za-z]+),([A-Za-z\sA-Za-z]+),([0-9]+).html$ rep.php?repID=$1&repName=$2&page=$3 [QSA]
#quotedetails.php rewrite this page url to Q99999.html
#e.g. quotedetails/$quoteID.html
RewriteRule ^quotedetails/(Q[0-9]+).html$ /quotedetails.php?quoteID=$1 [QSA]
#index/addquote/search/viewall/howto page rewrite *.php ---> *.html
RewriteRule ^index.html$ index.php [QSA]
RewriteRule ^addquote.html$ addquote.php [QSA]
RewriteRule ^search.html$ search.php [QSA]
RewriteRule ^viewall.html$ viewall.php [QSA]
RewriteRule ^customer.html$ customer.php [QSA]
RewriteRule ^addcustomer.html$ addcustomer.php [QSA]
RewriteRule ^howto.html$ howto.php [QSA]
RewriteRule ^nice404.html$ nice404.php [QSA]
ErrorDocument 404 /auma_quotes/nice404.html

RewriteRule ^quotedetails/(Q[0-9]+).html$ /quotedetails.php?quoteID=$1 [QSA] is the wrong way around isnt it? it should be RewriteRule pattern match, so
RewriteRule ^quotedetails.php?quoteID=(Q[0-9]+)$ quotedetails/$1.html [QSA]
Hope this helps
Luke

Related

Remove %2523 from url and redirect to new, without that using .htaccess

I don't have an idea how can I remove %2523 from URL made by GET in php. I want to redirect users to page without that. Sometimes it has # on string beggining, and that's why it generates that "%2523".
For example, want to redirect them from something like:
localhost/catalog/value/%2523string
to
localhost/catalog/value/string
My current .htaccess file:
Options -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/catalog/value\.php\?value=([^/]*)\s [NC]
RewriteRule ^ /catalog/value/%1? [R=301,L]
RewriteRule ^catalog/([^/]*)$ /value/value.php?color=$1 [L]
Hopefully you can help me with that, trying from yesterday and still didn't nothing works.
Finally i solved that by adding this at the .htaccess beggining:
RewriteRule ^([^%]*)\%23(.*)$ /catalog/value/$2 [R=301,L]

url mod rewriting multiple parameters

I have these rules that i want to make it work.
RewriteEngine on
RewriteRule ^/(view|show)/(ebook|lecture)/?$ page1.php?a=$1&b=$2 [L,QSA]
RewriteRule ^/(view|show)/(ebook|lecture)/([^/]+)/?$ page2.php?a=$1&b=$2&c=$3 [L,QSA]
RewriteRule ^/([^/]+)/-page-([0-9]+)?$ page3.php?a=$1&b=$2 [L,QSA]
My links are normally like this
www.domain.com/page1.php?a=view&b=ebook
www.domain.com/page2.php?a=view&b=ebook&c=title
www.domain.com/page3.php?a=title&b=6
and i want to turn them like the following look
www.domain.com/view/ebook //page1
www.domain.com/view/ebook/title //page2
www.domain.com/title/page-6 //page3
I've tried my rules but only the first one worked, But the page didn't load and the style was literally broken and not even a single image loaded or anything at all.
Try with:
RewriteEngine on
RewriteRule ^/?(view|show)/(ebook|lecture)/?$ page1.php?a=$1&b=$2 [L,QSA]
RewriteRule ^/?(view|show)/(ebook|lecture)/([^/]+)/?$ page2.php?a=$1&b=$2&c=$3 [L,QSA]
RewriteRule ^/?([^/]+)/page-([0-9]+)?$ page3.php?a=$1&b=$2 [L,QSA]
No leading slashes in left htaccess RewiteRule url (you can use RewriteRule ^(view...)
And you use only page- in your www.domain.com/title/page-6 //page3 link (not -page-)

htaccess won't work for directory

hello I am facing a problem with my htacess i have two php files that are used for URL rewriting first one is video.php and second one is channel.php. on homepage when I click any video its properly works for rewriting the url e.g.
mysite.com/video.php?url=1234
changes to that works properly for me
mysite.com/1234-video-custom-slug
but when I click for any channel it loads the same video.php but with rewriting urls of channel like:
mysite.com/channel/1-channel-slug
instead of rewriting urls from channel.php?id=1
I don't know what i am doing wrong here is my htaccess file code
RewriteEngine On
RewriteRule ^([a-zA-Z0-9-/]+)$ video.php?url=$1
RewriteRule ^([a-zA-Z0-9-/]+)/$ video.php?url=$1
RewriteRule ^channel/([a-zA-Z0-9-/]+)$ channel.php?id=$1
RewriteRule ^channel/([a-zA-Z0-9-/]+)/$ channel.php?id=$1
Change the order like this
RewriteEngine On
RewriteRule ^channel/([a-zA-Z0-9-/]+)$ channel.php?id=$1
RewriteRule ^channel/([a-zA-Z0-9-/]+)/$ channel.php?id=$1
RewriteRule ^([a-zA-Z0-9-/]+)$ video.php?url=$1
RewriteRule ^([a-zA-Z0-9-/]+)/$ video.php?url=$1

Static url does not redirect to the requested page

I have a question regarding the .htaccess file.
I have rewritten a dynamic url in a static one as following:
www.mysite.com/index.php?lang=IT
in
www.mysite.com/it
using this rewrite rule:
RewriteEngine On
RewriteRule ^it/([^/]*)\.html$ /index.php?lang=$1 [L]
So far so good...
Now I need to create another static url for a dynamic url which redirects to the product description
www.mysite.com/product_details.php?id=1485
The rule inserted in the .htaccess is:
RewriteEngine On
RewriteRule ^it/prodotto-([^-]*)-([^-]*)\.html$ /it/product_details.php?id=$1&lang=$2 [L]
Unfortunately if I click on the related link I cannot reach the requested page; but if I comment the first rule like this
#RewriteRule ^it/([^/]*)\.html$ /index.php?lang=$1 [L]
then I can see the page.
Do you know how to solve this issue?
Assuming that lang equals to language you want the script do like so?
RewriteEngine On
RewriteBase /
RewriteRule ^it/([^/]*).html$ /index.php?lang=$1 [L]
RewriteRule ^it/prodotto-([^/]*)-([^/]*).html$ /it/product_details.php?id=$1&lang=$2 [L]
this will do
yoursite.com/it/$1.html
and
yoursite.com/it/prodotto-$1-$2.html
?

Rewrite rules not working htaccess

I have the following htaccess rewrite rules
RewriteRule ^shows-watch/(.*).html?$ show.php?name=$1
RewriteRule ^shows-watch/(.*)/season-(.*).html?$ show.php?name=$1&season=$2
RewriteRule ^shows-watch/(.*)/season-(.*)/episode-(.*).html?$ show.php?name=$1&season=$2&episode=$3
Now the thing is, the first rewrite rule works just fine
RewriteRule ^shows-watch/(.*).html?$ show.php?name=$1
It's just when I try using the others, only name get variable is being passed and not
$_GET['season']
or
$_GET['episode']
i know it's most likely something simple I'm missing or have done, but I just can't seem to get it working.
Give this a try:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^shows-watch/([^/]+)/season-([^/]+)/episode-([^/]+).html?$ show.php?name=$1&season=$2&episode=$3 [QSA,NC,L]
RewriteRule ^shows-watch/([^/]+)/season-([^/]+).html?$ show.php?name=$1&season=$2 [QSA,NC,L]
RewriteRule ^shows-watch/([^.]+)\.html?$ show.php?name=$1 [QSA,NC,L]
The order is very important so they don't overlap you also need the L flag to stop when needed.
This assumes your .htaccess is on the root folder of your domain along with the show.php file and that you are accessing it like this:
domain.com/shows-watch/Show Name.html
domain.com/shows-watch/Show Name/season-1.html
domain.com/shows-watch/Show Name/season-1/episode-10.html
The first line gets all the links because it matches all the links.
Try reverse the order:
RewriteRule ^shows-watch/(.*)/season-(.*)/episode-(.*).html?$ show.php?name=$1&season=$2&episode=$3
RewriteRule ^shows-watch/(.*)/season-(.*).html?$ show.php?name=$1&season=$2
RewriteRule ^shows-watch/(.*).html?$ show.php?name=$1
Or you can exclude slashes like this:
RewriteRule ^shows-watch/([^/]*).html?$ show.php?name=$1
RewriteRule ^shows-watch/([^/]*)/season-([^/]*).html?$ show.php?name=$1&season=$2
RewriteRule ^shows-watch/([^/]*)/season-([^/]*)/episode-([^/]*).html?$ show.php?name=$1&season=$2&episode=$3

Categories