.htaccess rewrite rule not working - apache

I've been looking few different tutorials about it like
https://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/
and I thought it would be easy to do my own rewrite rule but I don't know why it's not working.
this is what I have in my htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wp2/
RewriteRule ^lol portafolio [NC,L] # Change feed URL
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp2/index.php [L]
</IfModule>
# END WordPress
and when I write wwww.domain.com/wp2/lol it's not redirecting me to wwww.domain.com/wp2/portafolio which this code:
RewriteRule ^lol portafolio [NC,L] # Change feed URL
should do.. I guess it's not correct. Why it's not doing the rewriting correctly? I need to rewrite a bunch of URLS.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

Try this code. it will help you
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

Related

Having trouble with godaddy htaccess file

RewriteEngine On
RewriteBase /
RewriteRule ^/?$ /1 [L]
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^sayfa-([0-9a-zA-Z-_]+) menu-detay.php?sef=$1 [L,QSA]
RewriteRule ^kategori-([0-9a-zA-Z-_]+) kategoriler.php?sef=$1 [L,QSA]
RewriteRule ^urun-([0-9a-zA-Z-_]+)-([0-9]+)$ urun-detay.php?sef=$1&urun_id=$2 [L,QSA]
RewriteRule ^urun-([0-9a-zA-Z-_]+) urun-detay.php?sef=$1 [L,QSA]
RewriteRule ^bize-ulasin$ iletisim.php [NC,L]
RewriteRule ^sitemap.xml$ sitemap.php [NC,L]
</IfModule>
This is my htaccess file and seo links are not working. Im using LINUX hosting and couldnt find anything helpfull.
When i click my seo url on my index like "website.com/product-33v-new-generation" it redirect me to homepage.
RewriteRule ^urun-([0-9a-zA-Z-_]+)-([0-9]+)$ urun-detay.php?sef=$1&urun_id=$2 [L,QSA]
This is my seo url link for products
RewriteRule ^kategori-([0-9a-zA-Z-_]+) kategoriler.php?sef=$1 [L,QSA]
And this one is for categories.
But non of them are working for somehow. I have another linux hosting but they are working just fine.
Any help appericiated.
With your shown samples, please try following htaccess Rules. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine On
RewriteBase /
RewriteRule ^/?$ index.php [L]
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
##RewriteRule ^(.*)/?$ index.php [L]
RewriteRule ^ index.php [L]
RewriteRule ^sayfa-([0-9a-zA-Z-_]+) menu-detay.php?sef=$1 [NC,L,QSA]
RewriteRule ^kategori-([0-9a-zA-Z-_]+) kategoriler.php?sef=$1 [NC,L,QSA]
RewriteRule ^urun-([0-9a-zA-Z-_]+)-([0-9]+)$ urun-detay.php?sef=$1&urun_id=$2 [NC,L,QSA]
RewriteRule ^urun-([0-9a-zA-Z-_]+) urun-detay.php?sef=$1 [L,QSA]
RewriteRule ^bize-ulasin/?$ iletisim.php [NC,L]
RewriteRule ^sitemap\.xml/?$ sitemap.php [NC,L]
</IfModule>
Few fixes in OP's tried htaccess Rules file:
You need NOT to use multiple <IfModule mod_rewrite.c> sections as per your shown attempts.
Need not to use multiple RewriteBase, you could mention it in starting of Rules.
Also fixed few Rules flags and regex in few of the other rules here.

htaccess redirect if one query param matches

I'm trying to redirect from /somedir/index.php?action=something&id=x to /index.php?action=something&id=x
Only if action = something. id is dynamic.
Most recently I've tried this with no luck. What is wrong with this?
<IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} (^|&)action=something($|&)
RewriteCond %{QUERY_STRING} (^|&)id=($|&)
RewriteRule ^somedir/index\.php$ /index.php?action?something&id=%2$ [NC,R]
</IfModule>
Note: somedir has an index.php and this rule in its htaccess. Will that result in conflicts?
RewriteRule ^.*$ index.php [NC,L]
Try this rule instead of your rule in .htaccess
<IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} (^|&)action=something($|&)
RewriteCond %{QUERY_STRING} (^|&)id=x($|&)
RewriteRule ^somedir/index\.php$ /index.php?action=something&id=x [L,R=301]
</IfModule>
The result will not conflict.
You can use:
<IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} (?:^|&)(action|id)=([^&]+)&(?:.*&)?(action|id)=([^&]+)(?:$|&) [NC]
RewriteRule ^somedir/index\.php$ /index.php?%1=%2&%3=%4 [NC,L,R=301]
</IfModule>

Url friendly htaccess PHP

I have a product page and need the user to access it , but with the product name.
How it works: localhost/product?id=2
I want it that way: localhost/computer
My code .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^confirmation/?$ confirmation.php [NC,L]
RewriteRule ^/product/([^/]+)/$ product.php?id=$1 [QSA,L]
</IfModule>
Is not working, where I'm going wrong ?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^confirmation/?$ confirmation.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?([^/]+)/?$ product.php?id=$1 [QSA,NC,L]
</IfModule>

Remove specific slug in with htaccess

I have a Wordpress site web in localhost with XAMPP. Now I have a URL like this:
http://localhost:82/subdirectory/images.html/nggallery/tags/[tagname]
Now I want this:
http:// localhost:82/subdirectory/images/nggallery/[tagname]
To remove tags, I've tried many codes, like this:
RewriteRule ^tags/(.+)/$ /$1 [R=301,L]
but doesn't work.
Help me, please.
I'm using WordPress, my htaccess file looks like this
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdirectory/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subdirectory/index.php [L]
</IfModule>
# END WordPress
Before answering, a better idea than using htaccess for this is to use Wordpress' rewrite modules.
Anyway, you need to put your specific rules before Wordpress' main rule.
You can replace your current code by this one in your htaccess (which has to be in your subdirectory folder)
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /subdirectory/
# redirect /.../tags/XXX to /.../XXX
RewriteCond %{THE_REQUEST} /images\.html/nggallery/tags/([^\s\?]+)\s [NC]
RewriteRule ^ images/nggallery/%1? [R=301,L]
# internally rewrite /.../XXX to /.../tags/XXX
RewriteRule ^images/nggallery/(.+)$ images.html/nggallery/tags/$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>
# END WordPress
try
http:// localhost:82/subdirectory/images/nggallery/[tagname]
RewriteRule ^nggallery/tags/(.*)$ http://localhost:82/subdirectory/images/nggallery/$1

rewrite htaccess from xyz.com/?type=test&s=test2 to xyz.com/test/test2

what i need is for a search thing, so the test2 is changeable and need the link to change too.
how can i do this in .htaccess?
this is what i thought to do.
RewriteRule ^xyz.com/test/(.*)$ ^xyz.com/?type=test&s=$1 [NC,L]
any idea?
Thanks!
my Wordpress .htacess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^([^/]+)/(.*)$ index.php?type=test&s=$1 [NC,L]
</IfModule>
# END WordPress
You will be looking at something like this:
RewriteRule ^([^/]+)/(.*)$ ?type=$1&s=$2 [NC,L]
Not sure it will work without the filename, though. If that's the case point the rewrite to your file that handles requests, e.g.:
RewriteRule ^([^/]+)/(.*)$ index.php?type=$1&s=$2 [NC,L]
You don't include the domain name in the RewriteRule match pattern.