I am looking for a script to convert short domain link to main domain URL such as the below example? It's like Facebook.com/username , it will automatically redirect you to the complete URL www.facebook.com/username
When user type short domain = http://abc.com/leon
the system should automatically CONVERT IT TO main domain URL = http://www.abc.com/leon
Do i need to edit any on the .htaccess? If so, what is the script should i add?
I have tried the following script on .htaccess , but it doesn't convert to main URL
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^([a-zA-Z]+)$ /Test.php?pname=$1 [L,QSA]
Please help.
Cheers
Alright... Identified this may be under the category of DNS issue and found this link => Best way to redirect non-www to www? ; as well the following script seem work
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.youraddress.com$ [NC]
RewriteRule ^(.*)$ http://www.youraddress.com/$1 [R=301,L]
Related
I have a web with 3 domains. com, .de, .co.uk. One domain for one language.
By now the languages are in .com and it runs like this:
www.domain.com/?lang=de
www.domain.com/?lang=en
www.domain.com/?lang=fr
But now I need the web not accessible with www.domain.com/?lang=en and automaticaly redirect to www.domain.co.uk
I've tryed with:
RewriteEngine On
RedirectMatch de$ http://www.domain.de
But don't works for me.
Anyone knows how can I do this?
Thank you very match in advance.
You should use the QUERY_STRING Rewrite-Condition to check for query parameters. e.g.:
RewriteCond %{QUERY_STRING} ^lang=de$
RewriteRule ^/$ http://www.domain.de [R,L]
I have a url as below.
http://example.com/listing?listingid=237508&2000
What I want is to redirect it to a mobile version of the site.
http://example.com/mobile-listing?listingid=237508&2000
The problem is that if it is example.com/listing it should redirect to example.com/mobile-listing. If it is example.com/event it should redirect to example.com/mobile-event and so on. How am I to do this? I have seen question about redirection to mobile version based on url parameters or getvalue. But not this way. Any help would be greatly appreciated. Thanks.
i've found a simuluar answer from ulrich palha which might helps.
question id 9113747
in the .htaccess file of root you can try this:
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} (^|&)listingid= [NC]
RewriteRule ^ mobile-listing [L,R=301]
hopes this helps. you might change a little and this should point in the right direction to the solution.
You need to use a RewriteRule directive and QSA and PT flags
<VirtualHost *:80>
RewriteEngine on
RewriteRule ^/listing$ /mobile-listing [PT,QSA]
…
</VirtualHost>
Flags
PT:
Forces the resulting URI to be passed back to the URL mapping engine
for processing of other URI-to-filename translators, such as Alias or
Redirect. details ...
QSA:
Appends any query string from the original request URL to any query
string created in the rewrite target.details
More information
You can find more scenarios at Redirecting and Remapping with mod_rewrite.
Without any sort of condition for what is mobile or what isn't, and you always redirect, then the rule would look something like this:
RewriteCond %{REQUEST_URI} !^/mobile-
RewriteRule ^([^/]+)$ /mobile-$1 [L,R]
The query string will automatically get appended. Change the R to R=301 if you want to permanently redirect.
I have a requirement where in I want to give users of my site their personal url.
Something like "http://abc.example.com" and when any user types this url in browser it should open this link "http://www.example.com/index/sub-domain?username=abc"
So I tried writing and trying many codes and finally was successful with below code but problem is it redirects. I want an internal redirection. URL address window should remain as "http://abc.example.com".
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^.*$ index.php [NC]
RewriteCond %{HTTP_HOST} !^www.
RewriteCond %{HTTP_HOST} ^([a-z]+)\.example.com$
RewriteRule ^(.*)$ http://www.example.com/index/sub-domain?username=%1
</IfModule>
I am not sure if It is possible or not ? Any advice or help will be of great help. Also can anyone suggest me some .htaccess tutorial.
If you do not specificy the R flag on your RewriteRule, mod_rewrite normally performs an internal rewrite. However, since you are using an absolute URL as your rewrite target, it has to be the exact same host, otherwise an external redirect will be issued.
If you really wish to internally redirect to another host, you should check out mod_proxy.
Could someone tell me how to rewrite this URL. I have looked at a lot of questions on stackoverflow but they seem to be missing my answer.
RewriteEngine On
That is what I have... its a bit poor.
I need to rewrite url's if they do not point to a directory.
I need to do this...
any.domain.com/pages/some-page-slug/login
To be rewritten to the correct url of...
any.domain.com/pages/login.php?page=32
Does anyone have any ideas on how this can be achieved?
1) Rewriting product.php?id=12 to product-12.html
It is a simple redirection in which .php extension is hidden from the browser’s address bar and dynamic url (containing “?” character) is converted into a static URL.
RewriteEngine on
RewriteRule ^product-([0-9]+)\.html$ product.php?id=$1
2) Rewriting product.php?id=12 to product/ipod-nano/12.html
SEO expert always suggest to display the main keyword in the URL. In the following URL rewriting technique you can display the name of the product in URL.
RewriteEngine on
RewriteRule ^product/([a-zA-Z0-9_-]+)/([0-9]+)\.html$ product.php?id=$2
3) Redirecting non www URL to www URL
If you type yahoo.com in browser it will be redirected to www.yahoo.com. If you want to do same with your website then put the following code to .htaccess file. What is benefit of this kind of redirection?? Please check the post about SEO friendly redirect (301) redirect in php and .htaccess.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^optimaxwebsolutions\.com$
RewriteRule (.*) http://www.optimaxwebsolutions.com/$1 [R=301,L]
4) Rewriting yoursite.com/user.php?username=xyz to yoursite.com/xyz
Have you checked zorpia.com.If you type http://zorpia.com/roshanbh233 in browser you can see my profile over there. If you want to do the same kind of redirection i.e http://yoursite.com/xyz to http://yoursite.com/user.php?username=xyz then you can add the following code to the .htaccess file.
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1
5) Redirecting the domain to a new subfolder of inside public_html.
Suppose the you’ve redeveloped your site and all the new development reside inside the “new” folder of inside root folder.Then the new development of the website can be accessed like “test.com/new”. Now moving these files to the root folder can be a hectic process so you can create the following code inside the .htaccess file and place it under the root folder of the website. In result, www.test.com point out to the files inside “new” folder.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^test\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.test\.com$
RewriteCond %{REQUEST_URI} !^/new/
RewriteRule (.*) /new/$1
TO do this you need to write a front controller.
See here, here, here, and here.
Alternatively in Apache you can rewrite this
any.domain.com/pages/32/login
or this:
any.domain.com/32/login
or even this:
any.domain.com/some-slug/32/login
to this:
any.domain.com/pages/login.php?page=32
One way or another to do this with only apache you need to supply the page id in some fashion. Keep in mind even with format any.domain.com/some-slug/32/login the content of the slug is irrelevant and won't necessarily link to the correct page. Which I imagine is undesirable and bad for SEO.
Another alternative is using RewriteMap. But this will be tricky and require reloading apache configurations whenever a page/slug is created/edit.
I understand that pages and login are static in this case and some-page-slug is changing. And you always want to redirect to static page /pages/login.php?page=32
So this is how to do it:
1) Rewrite
RewriteEngine On
RewriteRule ^pages/([a-zA-Z0-9_]+)/login(.*)$ /pages/login.php?page=32
or 2) Redirect Pernament
RewriteEngine On
RewriteRule ^pages/([a-zA-Z0-9_]+)/login(.*)$ /pages/login.php?page=32 [R=301,L]
or 3) Redirect Temporary
RewriteEngine On
RewriteRule ^pages/([a-zA-Z0-9_]+)/login(.*)$ /pages/login.php?page=32 [R=302,L]
Here is great article about htaccess trics
http://perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/
I'm currently using an .htaccess to get round a problem with a CMS, nothing major and an htaccess fix is tidy enough.
I'm currently using the format...
redirect 301 /pictures.html http://www.domain.com/gallery.html
The problem though this causes is that the CMS uses pictures.html?vars=here to select galleries and so the redirect breaks this part of it. Is there any way I can redirect pictures.html but not when it has variables attached?
For example, add something like
RewriteCond %{QUERY_STRING} ^$
before your rule.
You can redirect everyone except your webserver by detecting the IP address like so:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_HOST} !^123\.45\.67\.89
RewriteRule \.html$ /alternate_page.html [R=301,L]