I have problem using .htaccess to rewrite some of the friendly URL.
The root URL is http://www.example.com/my/
The working call url is http://www.example.com/my/Post.php?id=2
Both .htaccess file and Post.php are located in the sub-directory http://www.example.com/my/
But I wanted it to be like the following:
http://www.example.com/my/job/kuantan/?id=2
The .htaccess configuration as below:
DirectoryIndex index.php
Options All -Indexes
#ErrorDocument 404 /404.php
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^job/kuantan/([0-9]+) /Post.php?id=$1 [L,QSA, NC]
BUT, once i deployed the above .htaccess configuration file, it prompted 500 internal error message as well.
Is something missing or wrong in the .htaccess configuration? Please advice and really appreciated if someone there could give a hand. Thanks.
You should just need a single rule:
RewriteRule ^/my/job/kuantan/$ /my/Post.php
The query string is carried over by default.
Assuming that .htaccess and Post.php are located in the sub-directory /my/:
DirectoryIndex index.php
Options All -Indexes
#ErrorDocument 404 /404.php
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^job/kuantan/([0-9]+)$ Post.php?id=$1 [L,QSA,NC]
Remove all spaces between []. Change /Post.php?id=1 to Post.php?id=$1.
You can have this code in /my/.htaccess:
DirectoryIndex index.php
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /my/
RewriteCond %{THE_REQUEST} /Post\.php [NC]
RewriteRule ^ job/kuantan [R=302,L,NE]
RewriteRule ^job/kuantan/?$ Post.php [L,NC]
Query String is automatically carried over so there is no need to capture it in rule.
Related
How do I redirect a link to a particular link using .htaccess
http://www.example.com/one http://differentdomain.co.uk/a/
http://www.example.com/two http://differentdomain.co.uk/b/
http://www.example.com/three http://differentdomain.co.uk/c/
http://www.example.com/four http://differentdomain.co.uk/d/
i have tried Redirect 301 & RewriteRule but its not working at all, im using an apache server
This is what i have on my .htaccess file
<IfModule mod_rewrite.c>
#Options +FollowSymLinks
#Options +Indexes
RewriteEngine On
#RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^/one http://differentdomain.co.uk/a/ [R=301,L]
</IfModule>
both these codes dont work for me
Redirect 301 /one/ http://differentdomain.co.uk/a/
RewriteRule ^/one http://differentdomain.co.uk/a/ [R=301,L]
by the way the domain I'm working on is empty only the .htaccess & cgi-bin folder is present
I think (not sure) Redirect directive doesn't work because you don't have /one path in your root.
try this :
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^one http://differentdomain.co.uk/a/ [R=301,L]
I want to redirect my file in folder A to folder B with the same file name.
EG.
yourdomain.com/folderA/nosedigger.php
to
yourdomain.com/folderB/nosedigger.php
The .htaccess is at yourdomain.com/folderA/.htaccess.
I tried the following but it does not work like a charm. Need help. Totally have no clue what the codes in .htaccess really mean.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/folderB/ [NC]
RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteRule ^ /folderB/$2 [R=301,L]
To redirect from foldera to folderb, you can use the following redirect above your other rules
RedirectMatch ^/foldera/(.*)$ /folderb/$1
this should be all you need:
RewriteEngine On
RewriteRule /folderA/(.*) /folderB/$1 [R=302,NC]
maybe:
RewriteRule ^folderA(/.*)?$ folderB$1 [R=302,NC]
I'm trying to redirect a folder to a file.
I want to redirect:
www.mysite.com/category/customername
AND
www.mysite.com/category/customername/
TO
www.mysite.com/category.php?customer=customername
This is working, but "customer" become "customername.php" and not "customer"
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^category/(.*)$ category.php?customer=$1 [L]
How could i remove ".php" via .htaccess?
Thank you!
You can use:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^category/([\s\w-]+)/?$ category.php?customer=$1 [L,NC,QSA]
Thank you anubhava, i have do a dynamic rule:
RewriteRule ^(.+[^/])/(\w+)/?$ $1.php?customer=$2 [L]
Tested for
www.mysite.com/category_1/customer AND
www.mysite.com/category_1/customer/
www.mysite.com/category_2/customer AND
www.mysite.com/category_2/customer/
www.mysite.com/category_X/customer AND
www.mysite.com/category_X/customer/
Bye
i need help in URL rewriting of my own. My URL structure is looks like
http://domain.com/products-details.php?id=14
What i want it to be something like http://domain.com/products/14/
What i have tried so far is this in my .htaccess file
ErrorDocument 404 /myproject/notfound.php
Options +FollowSymlinks
RewriteEngine on
RewriteBase /myproject/
RewriteRule ^products/([^/]+)$ products-detail.php?id=$1 [QSA]
The above rule works fine without the trailing slash at the end, but i do want the slash at the end.
Further more:
It would be great if the non-rewrite request gets redirected to the rewrite ones. Thank you:)
You need a new rule for redirect:
ErrorDocument 404 /myproject/notfound.php
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /myproject/
RewriteCond %{THE_REQUEST} /products-detail\.php\?id=([^\s&]+) [NC]
RewriteRule ^ products/%1? [R=302,L,NE]
RewriteRule ^products/([^/]+)/?$ products-detail.php?id=$1 [NC,L,QSA]
I had a paid domain, I did put a folder with the name of the domain (mysite.net) in the server
I don't want to pay for the domain anymore, so I want to use the default subdomain given by my hosting service (mysitenet.ipage.com) but the problem is what I said above, it exists a folder with the name of my paid domain, like this:
/
/mysite.net
/cgi.bin
I read this solution to try redirection:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/mysite.net[NC]
RewriteRule ^ /mysite.net%{REQUEST_URI} [R=301,L]
with this rules I go to mysitenet.ipage.com and redirects me to mysitenet.ipage.com/mysite.net as I want, but is there a way to hide the 'mysite.net' part?
You can put this code in your htaccess (which has to be in root folder)
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^(?!mysite\.net/)(.*)$ mysite.net/$1 [L,QSA]
EDIT: if you want to avoid duplicate content and also redirect /mysite.net/something to /something
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/mysite\.net/([^\?\s]+) [NC]
RewriteRule ^ %1 [R=301,L]
RewriteRule ^(.*)$ mysite.net/$1 [L,QSA]