Using CF to detect if URL is index.cfm or / - iis

I'm not sure whether this is possible or not using the CGI scope, but what I'm trying to do is detect if a user is browsing a page that is /index.cfm or /.
In the event of it being /index.cfm I would like to do a 301 redirect to the /.
I've viewed a dump of the CGI & URL scopes but can't see any easy method of redirecting based on this.
Any ideas greatly appreciated.
We are using ColdFusion 10.

Just an idea: why don't you use the rewrite module from Microsoft http://www.iis.net/downloads/microsoft/url-rewrite and do something like
^/index.cfm / [L,R=301]

In CF you can try like this:
<cfif listlast(cgi.script_name, "/") eq "index.cfm">
<cflocation url="redirectlogin.cfm" addtoken="no" statuscode="301">
</cfif>

Because we are using IIS, we have applied this
<cfset stHttpRequestData = getHttpRequestData()>
<cfif stHttpRequestData.headers["X-REWRITE-URL"] IS "/index.cfm">
<cflocation url="http://www.domainname.com/" addtoken="no" statuscode="301">
</cfif>

Related

Using Rewrite Rule in .htaccess not working

I am trying to use Rewrite to display a nice SEO friendly url instead of an ugly one.
Ugly URL
https://domain.co/blog-detail?data=how-important-is-teeth-cleaning-for-kids
Pretty URL
https://domain.co/blog-detail/how-important-is-teeth-cleaning-for-kids
Here Ugly URL is using 'data' variable value to populate page HTML.
Rewrite condition used
RewriteRule ^blog-detail/([A-Za-z0-9]+)$ blog-detail?data=$1
^^This does nothing.

Need to Redirect Category Page On Home Page of Lightspeed Based Webstore

I have some trouble with redirection of my category page to Home page.
Have category page www.example.com/sale-baby that want to redirect on home www.example.com from .Htacess.
Using Lightspeed Webstore for the website.
I try to use simple rule but its not working.
If possible can give right suggestion for that.
Thanks
Adam
RewriteEngine On
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]
“L” indicates that it’s the last instruction and “R” means redirect, and “301” means a permanent redirect.
other way:
Position the cursor after the HEAD tag in the code.
http://www.newsite.com/newurl.html">
Hope it Help You..

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 –

Multiple subdirectory error with mod_rewrite

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

Resources