Multiple subdirectory error with mod_rewrite - .htaccess

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/".

Related

Problem of links when create friendly links with htaccess [duplicate]

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.

htaccess not working properly for sub url having more slashes

I am having 2 websites. Call it 5p_front (http://localhost/5p_front/) (Developed in OctoberCMS) and 5p_group (http://localhost/5p_group/) (Developed in CakePHP)
In 5p_front i have an .htaccess file and in which i put a condition which will redirect to 5p_group website as soon as it finds a word having 5p_group_login in url. Here is code below
.htaccess
RewriteRule ^5p_group_login.*$ http://localhost/5p_group [L,R=301]
So if someone tries to go here for example http://localhost/5p_front/5p_group_login , they will simply be redirected to here http://localhost/5p_group/ .
This works fine from home page and other subpages like about page for example http://localhost/5p_front/we-are-5p-group .
However i have one product inner page http://localhost/5p_front/product/10 and if i hover the menu item which allows me to redirect to login page, it is showing this url http://localhost/5p_front/product/5p_group_login and hence when i click on it, i am unable to redirect at http://localhost/5p_group/ as it is only recirecting to this current url only http://localhost/5p_front/product/5p_group_login which should not be the case.
Additionally, My Menu is coming dynamically and i have used Static Pages plugin to create menus which OctoberCMS provides and i have created "Login" menu link like below.
How can i redirect the url at http://localhost/5p_group/ even if the user is at http://localhost/5p_front/product/10 and clicks on "Login" link which is showing http://localhost/5p_front/product/5p_group_login if i mouse hover on it.
Can someone guide me here what should i do in this scenario.
Thanks
Your rule
RewriteRule ^5p_group_login.*$ http://localhost/5p_group [L,R=301]
when placed in 5p_front/.htaccess will affect only URIs that begin with /5p_front/5p_group_login (because of the leading ^ in your pattern) so /5p_front/product/5p_group_login will not match.
If you want to rewrite URLs that have 5p_group_login anyhwere, just use:
RewriteRule 5p_group_login http://localhost/5p_group [L,R=301]

SPA .htaccess breaks JS files after top level [duplicate]

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.

Convert to SEO friendly URL

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

.htaccess correct format for RewriteRule

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 –

Resources