This question already has answers here:
Absolute urls, relative urls, and...?
(5 answers)
Closed 7 years ago.
I have problem when using htaccess rewriteurl, it was stacking every I change the page,
I try this one :
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^category/([^/]*)/([^/]*)$ /test/category.php?k=$1&page=$2 [L]
change this
http://localhost/test/category.php?k=fashion&page=2
become like this
http://localhost/test/category/fashion/2
the problem occure when i'm going to page 3
URL become like this
http://localhost/test/category/fashion/category/fashion/3
so on...
switch page to page 4
http://localhost/test/category/fashion/category/fashion/category/fashion/3
why is this looping?
what's wrong with my code??
Because you've changed your URL's to look like http://localhost/test/category/fashion/2, any relative links on that page will think the new URL base is: http://localhost/test/category/fashion/ instead of http://localhost/test/, which would be the base if the browser loaded http://localhost/test/category.php?k=fashion&page=2. Because of this, you either need to make all your links absolute URLs or add the base in you html header:
<base href="/test/" />
Related
I want to make my URL as SEO Friendly URL. I tried editing .htaccess file by rewriting rule
RewriteRule ^swift-details/([0-9]+)/([0-9a-zA-Z_-]+)$ swift-details.php?id=$1 [NC,L]
RewriteRule ^swift-details/(css|js|img)/(.*)?$ /$1/$2 [L,QSA,R=301]
It's routing the correct URL but in that page CSS JS and images are not working.
Example URL:
http://www.example.com/swift-details/2/abblinbb
This is because your relative URIs have their base changed. Originally, the base is / when the page is /swift-details.php?id=foo, and the browser properly fills in relative links with the / base. But when the browser goes to a page like /swift/details/foo the base suddenly becomes /swift/ and it tries to append that in front of all relative URLs and thus none of them load.
You can either make your links absolute, or change the URI base in the header of your pages (inbetween the <head> </head> tags):
<base href="/">
You dont need the second rewrite rule. Your CSS/JS paths are all 'relative' to your current location.
Your CSS exists here:
/css/normalize.css
Your page is looking here:
/swift-details/2/abblinbb/css/normalize.css
All you need is 'forward-slashes' before your CSS/JS paths.
I want to make my URL as SEO Friendly URL. I tried editing .htaccess file by rewriting rule
RewriteRule ^swift-details/([0-9]+)/([0-9a-zA-Z_-]+)$ swift-details.php?id=$1 [NC,L]
RewriteRule ^swift-details/(css|js|img)/(.*)?$ /$1/$2 [L,QSA,R=301]
It's routing the correct URL but in that page CSS JS and images are not working.
Example URL:
http://www.example.com/swift-details/2/abblinbb
This is because your relative URIs have their base changed. Originally, the base is / when the page is /swift-details.php?id=foo, and the browser properly fills in relative links with the / base. But when the browser goes to a page like /swift/details/foo the base suddenly becomes /swift/ and it tries to append that in front of all relative URLs and thus none of them load.
You can either make your links absolute, or change the URI base in the header of your pages (inbetween the <head> </head> tags):
<base href="/">
You dont need the second rewrite rule. Your CSS/JS paths are all 'relative' to your current location.
Your CSS exists here:
/css/normalize.css
Your page is looking here:
/swift-details/2/abblinbb/css/normalize.css
All you need is 'forward-slashes' before your CSS/JS paths.
I'm trying to make my website URLs SEO-friendly, and I'm having problems...
How can I change this URL:
http://www.example.com/media.php?album=Album_1&page=1
To this kind of URL:
http://www.example.com/media/Album_1/1
I've tried this code that works, but my CSS seems KO...
RewriteEngine On
RewriteRule ^media/(.*?)/([0-9]+)$ media.php?album=$1&page=$2
Your rule's target doesn't need the &, it should just be &. Apache will propery encode it as needed (like in the anchor link in the HTML returned in a redirect). The reason your css isn't working sounds like a relative vs absolute URL issue. If your css is linked like <link rel=stylesheet href="something.css">, the relative URL resolution ends up being /media/Album_1/something.css.
Try adding this in the headers of your pages:
<base href="/">
Try reading mod_rewrite apache documents or just searching 'mod_rewrite' This specific question was asked many times
I have a "JQueried" page using tabs - Tab A, Tab B etc the tabs hide/show content based on a link like this: Tab 1 I am using jQuery Address Plugin v1.4
http://www.asual.com/jquery/address/ to create new page titles and a new URL for each tab. If you do not know the Address Plugin recreates the URL so the link #tab1 creates the URL page.html#tab1 but without a page refresh. It also changes the page title but is there any way to create an RewriteRule so that http://domain/page.html#tab1 can be called by say http://domain/tab1.html (where tab1,tab2 etc. have proper names not tab!)
Have tried but don't seem to get it to work. e.g.
Options +FollowSymlinks
RewriteEngine on
RewriteRule about.html /test.php#tab1 [NC]
suggestions please. Thanks in advance - oh the htaccess will go in the actual root folder
Sorry, I checked \#, it didn't work for me either.
How about redirecting to test.php?hash=tab1, and then:
if (isset($_GET["hash"]))
header ( "Location: test.php#".$_GET["hash"] );
Based on my comment above - I have just found this stackoverflow.com/questions/8606127/mod-rewrite-hash-tags so I guess can't be done –
I am trying to use mod_rewrite manually in joomla, and I have the following Rule:
RewriteRule ^test/(t1|t2|t3)-(.*).html$ /index.php?option=com_jumi&fileid=39&$1=$2 [L,NC]
So that I want the url
http://www.mysite.com/index.php?option=com_jumi&fileid=39&t1=foo
be displayed like
http://www.mysite.com/test/t1-foo.html
The rule works correctly, but when I am in the rewritten page the links like
http://www.mysite.com/link.html
or
http://www.mysite.com/xxx/link.html
become
http://www.mysite.com/test/link.html
or
http://www.mysite.com/xxx/test/link.html
respectively.
any suggestions?
thank you
You are using relative urls in your page. Your page contains a link like <a href="link.html">... and the browser makes the links relative to the current 'folder', namely "test", so when clicked the browser loads /test/link.html.
You should just use root-relative urls. So the link should become more like <a href="/link.html">.... The leading '/' makes the browser load the page relative to the root ("/"), not relative to "/test/".