Mod_Rewrite file to subfolder in .htaccess - php

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

Related

Rewritting URL by htaccess

When i click on a link it should redirect to
for ex; www.domain.com/demo/item.php?item=abc&id=3
but in url it should show as www.domain.com/demo/abc/3
im Using
<IfModule mod_rewrite.c>
Options +SymlinksIfOwnerMatches
RewriteEngine on
RewriteRule ^demo/(.+) demo/item.php?item=$1&id=$2 [NC,L]
Please help
You can try with this one, it will not redirect your URL but if you execute your URL (www.domain.com/demo/abc/3) it will be work.
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^demo/([0-9a-zA-Z\s_]+)/([0-9]+)(/?)$ demo/item.php?item=$1&id=$2 [NC,L]
You could try like this after adding the rewritebase directive
RewriteEngine on
RewriteBase /
RewriteRule ^demo/([0-9a-zA-Z\s_]+)/([0-9]+)(/?)$ demo/item.php?item=$1&id=$2 [NC,L]

htaccess redirection in php

How can i redirect from www.example.com/dietitian/reema.verma.3 to www.example.com/dietitian/#/3 ? Please help.
Options +FollowSymLinks
RewriteEngine On
Redirect www.example.com/dietitian/reema.verma.3 www.example.com/dietitian/#/3
You can only match REQUEST_URI using RewriteRule or Redirect.
Use this rule:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^/?(dietitian)/.+\.(\d+)/?$ /project/$1/#/$2 [L,NC,NE,R=301]

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.

Rewrtting url by htaccess

localhost/visvabharati/archive.html/type/notice
this is my url.I want it to rewrite as
localhost/visvabharati/archive.php?type=notice
Please help me how would be the htaccess
currently using
AddHandler x-mapp-php5 .php
Options +FollowSymLinks
RewriteEngine on
#RewriteBase /
DirectoryIndex index.php?url_key=index [T=application/x-httpd-php,L]
RewriteRule ^([^/]*).html$ /index.php?url_key=$1 [T=application/x-httpd-php,L]
RewriteRule ^([^/]*).html-([^/]*)$ /index.php?url_key=$1&id=$2 [T=application/x-httpd-php,L]
But its giving 500.
Please Help me sort it out
Regards
This code here will do it for one page.
RewriteRule ^localhost/visvabharati/archive.html/(.+)/(.+) localhost/visvabharati/archive.php?$1=$2
If you need to do this for multiple pages, this should work.
RewriteRule ^localhost/visvabharati/(.+).html/(.+)/(.+) localhost/visvabharati/$1.php?$2=$3
Assuming visvabharati is a directory.
Place this in /visvabharati/.htaccess:
RewriteEngine on
RewriteBase /visvabharati/
RewriteRule ^([^.]+)\.html/([^/]+)/([^/]+)/?$ $1.php?$2=$3 [L,QSA,NC]
Also you need to remove all the code shown in your question.

apache rewrite static url to dynamic

I'm try to rewrite my url
http://www.domain.com/live/randomword
it should go rewrite to
http://www.domain.com/live/?cat=randomword
here are my tests:
RewriteRule ^live/(.*)$ /live/?cat=$1
RewriteRule ^live/(.*)$ live/?cat=$1
and all i have in the htaccess file is:
RewriteEngine on
You should try to add a RewriteBase / to your .htaccess and to suffix your rule with a [L] to say it's last rewrite rule ending with something like that:
RewriteEngine on
RewriteBase /
RewriteRule ^live/(.*)$ live/index.php?cat=$1 [L]
If this still doesn't work be sure to check that mod_rewrite is enabled
also you can do a [R,L] instead of [L] to see the redirection in the url and so have more info on what's going own.
hope this help
Have this code in your .htaccess file:
Options -MultiViews +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^live/(.*)$ /live/?cat=$1 [L,NC]
in rewrite rule the file name or extension in missing?
write rule like,
RewriteRule ^live/([a-zA-Z0-9_-]+)$ /viewcategory.php?cat=$1

Categories