.htaccess mod_rewrite pretty URLs - php

I'm trying to get my URLs from this:
www.exmple.com/test.php?type=abc&id=12345
to
www.exmple.com/rrr/abc
is it possible... ?
thanks

yes.possible
To solve this issue simply add the following to your htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com
RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /index.html HTTP/
RewriteRule ^index.html$ http://www.yoursite.com/ [R=301,L]
More resources here

Related

htaccess rewrite url parameter

I want to redirect
http://localhost:8080/mypproject/?supplier=test123
to
http://localhost:8080/myproject/?product_cat=test123
But I don't know how...
You can use this code in your /myproject/.htaccess file:
RewriteEngine On
RewriteBase /myproject/
RewriteCond %{QUERY_STRING} ^supplier=([^&]+) [NC]
RewriteRule ^/?$ ?product_cat=%1 [L,R=301]

Vanity URL not working

I am using htaccess to try and rewrite a url. I have tried about 10 versions of the code and examples but nothing makes any change. I know mod_rewrite is working because it is adding www to the url, but the vanity URL won't work.
RewriteRule ^franchise/([0-9]+)/?$ franchise-information.php?franchiseid=$1 [NC,L] # Handle product requests
Here is the .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^franchise/([0-9]*?)/$ franchise-information.php?franchiseid=$1 [NC,L]
</IfModule>
And here is the URL:
http://www.playballkids.com/franchise-information.php?franchiseid=162
You can use this code in your DOCUMENT_ROOT/.htaccess file:
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /franchise-information\.php\?franchiseid=([^\s&]+) [NC]
RewriteRule ^ franchise/%1? [R=302,L,NE]
RewriteRule ^franchise/(\d+)/?$ franchise-information.php?franchiseid=$1 [NC,L,QSA]

redirect "non-www" domain to "www"domain with .htaccess rewrite

I couldn't find the solution for "non-www" to "www" domain redirection. I have tried the following :
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.*) http://www.domain.com/$1 [L,R=301]
# Remove index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]
</IfModule>
So, how can I redirect, for example domain.com or www.domain.com to http://www.domain.com ?.
Something like should work :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
Here is what should help you:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
Can you try this ?
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
Seems apache mod_rewrite module is not enabled. So Make sure the Apache module mod_rewrite is enabled on your web server.
Try again this and see..It must work.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
See here - http://iyngaran.info, It is working. So no problem with the rule
How To Create Temporary and Permanent Redirects with Apache click hear
To automatically add a www to your domain name:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
or
.htaccess To Redirect URLs
To use htaccess to redirect URL just copy and paste the snippet below and replace example.com with your domain.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
More info true ans
Redirecting non-www to www with .htaccess

Need to rewrite URL in .htaccess?

i need to rewrite the urls as below from your help.
i have this url for search
search-job.php?category=Accountancy&emp_type=Long+Term&working_pattern=Full+Time&location=Algeria&search=Search+Job
to
search-job-in-Accountancy-for-Full+Time-in-Algeria.html
OR from this
search-job.php?category=2&emp_type=2&working_pattern=2&location=12&search=Search+Job
To this
search-job-2-2-2-12.html
i have already done this
job-detail.php?j=Exalture-Software-Labs-Pvt-Ltd-Application-Developer-Websphere-Commerce-Suite-ais-GBS-in-India-Full-Time-Mumbai-11.html
To This
job-detail/Exalture-Software-Labs-Pvt-Ltd-Application-Developer-Websphere-Commerce-Suite-ais-GBS-in-India-Full-Time-Mumbai-11.html
My .htaccess is below
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /temp
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+job-detail\.php\?j=([^\s&]+) [NC]
RewriteRule ^ job-detail/%1? [R=301,L]
RewriteRule ^job-detail/([^/]+)/?$ job-detail.php?j=$1 [L,QSA]
Pls provide some help.
You need these additional rules:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+search-job\.php\?category=([^&]*)&emp_type=([^&]*)&working_pattern=([^&]*)&location=([^&]*)&search=([^\s&]+) [NC]
RewriteRule ^ search-job-%1-%2-%3-%4? [R=301,L,NE]
RewriteRule ^search-job-([^-]*)-([^-]*)-([^-]*)-([^-]*) search-job.php?category=$1&emp_type=$2&working_pattern=$3&location=$4&search=Search+Job [L,QSA]

htaccess question

Hay, In Plesk it gives me the ability to add a subdomain to a domain say x.y.com, the problem is that www.x.y.com gets treated as another subdomain. Is there a way to direct all traffic from www.x.y.com to x.y.com? I tried doing this in php using the 300 header, but stuff like www.x.y.com/mypage, doesn't get redirected. Could i use the .htaccess file to redirect all this traffic?
Thanks
# you probably want www.example.com to forward to example.com -- shorter URLs are sexier.
# no-www.org/faq.php?q=class_b
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
</IfModule>
Source: http://html5boilerplate.com
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^www.domain.com [nc]
rewriterule ^(.*)$ http://domain.com/$1 [r=301,nc]
From: http://www.webconfs.com/how-to-redirect-a-webpage.php
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.x.y.com [NC]
RewriteRule ^(.*)$ http://x.y.com/$1 [R=301,L]

Categories