I want to make my user profiles 'pretty' as it were. Here is the regular URL:
site.com/user.php?user=Echo123
I want this to become:
Echo123.site.com
Please help :) Im a .htaccess newbie.
You should contact your web hosting provider or go to your web console and Go To Domains->Your Domain->DNS->CNAME and input the subdomain Echo123.yourdomain.com then input the forwarding url yourdomain.com/user.php?user=Echo123
Try something like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
RewriteRule ^(.*)$ http://example.com/user.php?user=%1/$1 [L,NC,QSA]
Related
I am facing the following problem:
I have a website in which the URLS currently look like:
/manufacturer/product/[ID].html
I have re-developed the website (Using Laravel) and now it just is:
/product/[ID]
I am wondering whether it is possible to use a .htaccess file to redirect all these links back to the new link? So, in essence, I would need to just capture the [ID] from the old link and redirect it back to the new link.
EDIT:
So the link will look something like this:
mysite.com/parts/apple/A-6-H0.htm
OR
mysite.com/microsoft/A-1-5F.htm
So both Apple, Microsoft and A- can change depending on what manufacturer and what the product is Does this make sense?
RewriteEngine On
RewriteRule ^parts/(?:[^/]+/)?(.*)\.html?$ /parts/$1/ [R=301,L]
That should take care of it.
Please Try this:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^{domain name}[nc]
RewriteRule ^(.*)$ {domain name}/$1 [r=301,nc]
Redirect 301 /manufacturer/product/$1.html product/$1.html
I want my site to act like this. If user inputs site.cz it should be redirected to site.eu/?lang=cs but the user should still see site.cz. Right now I have the following htaccess file:
RewriteCond %{HTTP_HOST} site\.cz [NC]
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://site.eu/?lang=cs [L,R=301]
which works great and redirects only .cz request (dont do anything with .eu requests) but it displays .eu/?lang=cs in final. Problem is that I dont only want to display site.cz all the time but also links like site.eu/folder1/file1/?lang=cs should be redirected to site.cz/folder1/file1/
Any ideas how to accomplish this?
Thanks in forward
Are you using XAMPP or a web host? Upon testing, URL rewriting isn't working in XAMPP.. Anyway, you can try to check this, just make sure that your two sites are hosted by the same web hosting account:
RewriteCond %{HTTP_HOST} site\.cz [NC]
RewriteRule ^(.*)$ http://site.eu/$1?lang=cs [P,L]
But it looks like your sites aren't hosted by the same hosting account as what you've said:
when I use [P] flag I get an error "Following URL was not found on this server" – horin
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.
I know there are plenty of questions like I asked, but searching all day the soluation, I didnt find right one that would work for me, therefore I asked question.
Here is .htaccess code I have to view user profiles:
RewriteRule ^users/([^/\.]+)/$ viewProfile.php?user=$1&%{QUERY_STRING}
RewriteRule ^users/([^/\.]+)/([^/\.]+)/$ viewProfile.php?user=$1&usr_profile=$2&%{QUERY_STRING}
And using this rewrite users profile URL is:
http://www.domain.com/users/username.html
Inside of this type of URL, I would like to create subdomain users URL, like:
http://username.domain.com
Can anyone suggest the solution?
Thanks a lot.
Make sure your vhost is setup to accept requests for *.domain.com. Then add this above your other rewrite rules:
RewriteCond %{HTTP_HOST} !^www [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
RewriteRule ^$ viewProfile.php?user=%1 [L,QSA]
I want to make my user profiles 'pretty' as it were. Here is the regular URL:
user.php?user=UserName
I want this to become:
user/Username
Please help :) Im a .htaccess newbie.
Try these directives:
RewriteEngine on
RewriteRule ^user/([^/]+)$ user.php?user=$1 [L,QSA]
This rule rewrites any request with a URL path of the form /user/foobar internally to /user.php?user=foobar.
RewriteRule ^user/(.+)$ user.php?user=$1 [L,QSA]