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-)
Related
A normal link of my site may look like this
mydomain.com/categorylist/8/Special_Single_Songs.html
I'm planning to change the URL pattern to something like
mydomain.com/categorylist/8-Special-Single-Songs.html
How can I redirect the old URL pattern to the new one using .htaccess redirect rule?
My .htaccess Rewrite rule look like this
RewriteRule ^categorylist/([0-9]+)/([0-9a-z]+)/([0-9]+)/(.*)\.html$ /index.php?pid=$1&sort=$2&page=$3 [L]
Try this code
RewriteRule ^categorylist/([0-9]+)/([0-9a-z]+)/([0-9]+)/(.*).html$ /index.php?pid=$1&sort=$2&page=$3 [L]
RewriteRule ^categorylist/([0-9]+)\-([0-9a-z]+)/([0-9]+)/(.*).html$ /index.php?pid=$1&sort=$2&page=$3 [L]
try this & put it on top after RewriteEngine on
RewriteRule ^categorylist([^_]*)_([^_]*_.*).html$ $1-$2 [L,NE]
RewriteRule ^categorylist([^_]*)_([^_]*).html$ /$1-$2 [L,NE,R=301]
note : big number of underscores can be a problem
I am trying to get my htaccess to rewrite the url to display two folders rather than two vars.
Here is my url:
www.MyWebsite.com/index.php?p=info&id=1234
That is actual url but I want it to display this:
www.MyWebsite.com/info/1234
Here is the code for the htaccess but it does not work for the second var.
DirectoryIndex index_good.html index.php
RewriteEngine On
RewriteBase /tjshow/
# RewriteRule ^([\w\-]+)/*$ ?p=$1 [L]
# RewriteRule ^([\w\-]+)/([\w\-]+)/*$ ?p=$1&id=$2 [L]
RewriteRule ^([\w\-]+)/*$ index.php?p=$1 [L]
RewriteRule ^([\w\-]+)/([\w\-]+)/*$ index.php?p=$1&id=$2 [L]
RewriteRule ^([\w\-]+)/([\w\-]+)/([\w\-]+)/*$ index.php?p=$1&id=$2&link=$3 [L]
The first one works fine but the second one is giving me a page but with all kinds of internal broken links and images.
This one works:
www.MyWebsite.com/index.php?p=info
And it displays this only, which is what I want it to do:
www.MyWebsite.com/info
But if I add the second var there like this
http://mywebsite.com/tjshow/second
Then the code breaks.
Try using this rule instead:
RewriteRule ^([^/]*)/([^/]*)$ /index.php?p=$1&id=$2 [L]
Using the above rule will leave you with the URL: www.MyWebsite.com/info/1234
Is it possible to somehow change my website links from:
domain.com/category.php?tag=test
domain.com/section.php?tag=test
domain.com/news.php?tag=test
into this:
domain.com/category-test
domain.com/section-test
domain.com/news-test
Thanks and have a good day!
You can achieve this using .htaccess and mod_rewrite. You'll need to create a .htaccess file with the following contents:
RewriteEngine On
RewriteBase /
RewriteRule ^category-([^/]+)/?$ category.php?tag=$1
RewriteRule ^section-([^/]+)/?$ section.php?tag=$1
RewriteRule ^news-([^/]+)/?$ news.php?tag=$1
Now, accessing domain.com/category-test/ will take you to category.php?tag=test.
If you'd prefer to have slashes instead of dashes, you can use:
RewriteRule ^category/([^/]+)/?$ category.php?tag=$1
RewriteRule ^section/([^/]+)/?$ section.php?tag=$1
RewriteRule ^news/([^/]+)/?$ news.php?tag=$1
RewriteRule ^category-([a-zA-Z0-9]+)$ category.php?tag=$1 [NC,L]
RewriteRule ^section-([a-zA-Z0-9]+)$ section.php?tag=$1 [NC,L]
RewriteRule ^news-([a-zA-Z0-9]+)$ news.php?tag=$1 [NC,L]
In "category.php" file get the tag $_GET['tag'];
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
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