.htaccess rewrite from base (http://domain.com/catch-this) - php

I wonder how I should do accomplish the following.
Catch URL's like the following:
http://domain.com/blue-boats send to myfile.php?header=1$
I don't want it to have this structure: http://domain.com/boats/blue-boats
I've tried this, but it doesn't work properly:
RewriteRule /$ myfile.php?header=$1

just put .htaccess in the documentroot of http://domain.com/ with similiar content to the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/([^/]*)/?$ /myfile.php?page=$1 [L]
</IfModule>

Try:
RewriteRule (.+) myfile.php?header=$1

Related

Rewrite query into path using htaccess

How can I make htaccess rewrite the following URL structure:
http://example.com/detail.php?id=polo&categ=wears
to
http://example.com/wears/polo/
I have tried the below code but it didn't work for me.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.+)/(admin|css|fonts|ico|include|js|images|img|products|slide)/(.*)$ $2/$3 [L]
RewriteRule ^(.*)/(.*)/$ detail.php?id=$1&categ=$2
</IfModule>
Your code works for me when I include the trailing slash in the URL.
working -> http://example.com/wears/polo/
not working -> http://example.com/wears/polo
Also, you need to exclude the slash character from the .* expression.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.+)/(admin|css|fonts|ico|include|js|images|img|products|slide)/(.*)$ $2/$3 [L]
RewriteRule ^([^/]*)/([^/]*)/?$ detail.php?id=$1&categ=$2
</IfModule>
Try this
RewriteEngine on
RewriteRule ^/(\w+)/(\w+)$ detail.php?categ=$1&id=$2 [NC,L]

How to change url like .php?name=neco to url /neco in .htaccess?

Ive been trying this commands, but with no luck :
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^product/(.*+) product.php?name=$1
Make sure your mod_rewrite rules are inside an IfModule:
<IfModule mod_rewrite.c>
#...
</IfModule>
The rule you have will reroute example.com/product/foo to example.com/product.php?name=foo.
If you want to route example.com/foo to example.com/bar.php?name=foo you can do this:
<IfModule mod_rewrite.c>
RewriteBase /
RewriteRule ^([^/]*)$ /bar.php?name=$1 [L]
</IfModule>
so it will looks like this?
Options +FollowSymLinks
RewriteEngine on
<IfModule mod_rewrite.c>
RewriteBase /
RewriteRule ^([A-Za-z0-9]+)$ product.php?name=$1 [L]
</IfModule>
Ive been trying lot of Rewrite Rules, but nothin happens the script and .htaccess are in same directory of course

Rewrite URL doesn't work in .htaccess file

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.

Mod Rewrite htaccess rewriterule

I now have:
Order deny,allow
Options +FollowSymlinks
RewriteEngine on
DirectoryIndex index.php
RewriteRule ^en/newsevents$ ?action=setLang&lang=eng&menuid=6 [L,QSA]
It loads my texts but thiks it must look in the /en folder.
This does work, but changes the url from localhost/en/newsevents to localhost/name/?action=setLang&lang=eng&menuid=6
I want that it still remains localhost/en/newsevents
RewriteRule ^en/newsevents$ `http://localhost/name/?action=setLang&lang=eng&menuid=6 [L,QSA]`
Just do this:
RewriteRule ^(en/newsevents)$ $1?action=setLang&lang=eng&menuid=6 [QSA,L]
You need to use passthrough
RewriteRule ^en/newsevents$ ?action=setLang&lang=eng&menuid=6 [PT,L,QSA]

rewriting url for query strings

Hi I want To Ask How Can I convert
http://abc.tk/comments.php?post_referrel_id=16
to
http://abc.tk/comments.php?post_referrel_id/16
using .htaccess mod_write
RewriteBase /
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteRule ^comments\.php\?post_referrel_id/([^/]*)$ /comments.php?post_referrel_id=$1 [L,QSA]
RewriteEngine on
RewriteRule comments.php?(.*)/(.*)/$ /comments.php?$1=$2 [L]
A URL rewrite wouldn't matter in this instance, as your still using query strings. It would make more since to eliminate the Query string all together with something like:
http://abc.tk/comments.php/post_referrel_id/16
Nevertheless, this can be achieved using .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule comments.php?post_referral_id/(.*)$ /comments.php?post_referral_id=$1 [L]
</IfModule>
Which will still use the same code, but be recognized by a different URL.
Check this out.
RewriteEngine On
RewriteBase /
RewriteRule ^comments\.php\?post_referal_id/([^/]*)$ /comments.php?post_referrel_id=$1 [L,QSA]

Categories