How to do Url rewriting for folders? - php

I need to rewrite the link below
www.website.com/folder1/folder2/index.php?name=value
to be like this :
www.website.com/folder1/folder2/name/
I tried htaccess with this line of code, but it doesn't work.
RewriteEngine on
RewriteRule ^name/([A-Za-z0-9-]+)/?$ index.php?name=$1 [NC,L]
Thank you in advance!

Insert this rule in /folder1/folder2/.htaccess:
RewriteEngine On
RewriteBase /folder1/folder2/
RewriteCond %{THE_REQUEST} /index\.php\?name=([^\s&]+) [NC]
RewriteRule ^ name/%1? [R=302,L,NE]
RewriteRule ^name/([A-Za-z0-9-]+)/?$ index.php?name=$1 [NC,QSA,L]

Related

HTACCESS - mod_rewrite

I would like to rename url www.mypage.com/index.php or www.mypage.com/index_cz.php (the same version of index - just in another language) to www.mypage.com/en or www.mypage.com/cz
I have this code in .htaccess
RewriteEngine On
RewriteRule ^index\.php$ /en/ [R=301,L]
RewriteRule ^index_cz\.php$ /cz/ [R=301,L]
It redirects me to www.mypage.com/en or www.mypage.com/cz but it gimme back NOT FOUND...
Really thanks for ur help
You can use:
RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.php[?/\s]
RewriteRule ^index\.php$ /en/ [R=301,L]
RewriteCond %{THE_REQUEST} /index_cz\.php[?/\s]
RewriteRule ^index_cz\.php$ /cz/ [R=301,L]
RewriteRule ^/en/?$ index.php [NC,L]
RewriteRule ^cz/?$ index_cz.php [NC,L]

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]

rewrite url www.xyz.com/index.php?id=xyz to www.xyz.com/xyz using htaccess

I want to include item details details.php if url has parameter id=xyz
rewrite
url www.example.com/index.php?id=xyz
to
www.example.com/xyz.html
using htaccess
htaccess i am using has
RewriteEngine On
RewriteBase /
RewriteRule ^([^.]+)\.html$ index.php?id=$1 [L,QSA,NC]
RewriteCond %{THE_REQUEST} \s/index\.php\?id=([_0-9a-zA-Z-]+)\s [NC]
RewriteRule ^%1? [R=301,L]
RewriteRule ^([_0-9a-zA-Z-]+)$ /index.php?id=$1 [L]
RewriteCond %{THE_REQUEST} \s/index\.php\?id=([_0-9a-zA-Z-]+)\s [NC]
RewriteRule ^ %1.html? [R=301,L]
RewriteRule ^([_0-9a-zA-Z-]+?)(?:\.html)?$ /index.php?id=$1 [NC,L]
worked perfect
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^([^.]+)\.html$ index.php?id=$1 [L,QSA,NC]
Use this .htaccess to rewrite:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)\.html$ index.php?id=$1 [L,QSA,NC]
</IfModule>
Make sure you have mod_rewrite enabled (use phpinfo() or apache_get_modules() in PHP if available)
Please try following configuration in your www.example.com/.htaccess file,
i just test it and work fun on my env.
//htaccess file content
RewriteEngine On
RewriteRule ^(\w+).html$ /index.php?id=$1 [L]

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]

rewrite url with slash using htaccess

Hello someone pls help me
I have this url which is dynamic
productSearch.php?id_category=8&id_size=23&id_colour=93
and i have to do this in
productSearch/8/23/93
i have try
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/(.+)\.php[^\s]* [NC]
RewriteRule ^ /%1 [R=301,NE,L]
RewriteCond %{THE_REQUEST} \s/+id_category(?:\.php)?\?id=([0-9]+) [NC]
RewriteRule ^ id_category/%1? [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [QSA,NC,L]
its remove .php only but not putting slash.
Pls some one give me some idea
Try this
RewriteEngine On
RewriteRule productSearch/(\d+)/(\d+)/(\d+)$ productSearch.php?id_category=$1&id_size=$2&id_colour=$3 [L]
RewriteEngine On
RewriteBase /
Options -MultiViews
RewriteRule ^productSearch/([^/]*)/([^/]*)/([^/]*)$ productSearch.php?id_category=$1&id_size=$2&id_colour=$3 [L]
Try this. Put in your url following links: lala
If you want that only a numeric path will be rewritten you could use ([0-9]+) instead of ([^/]*)

Categories