i got a problem with rewriting my edit.php?id=1 to edit/id/1. Right now i have the following in my .htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^edit/id/([^/.]+)$ edit.php?id=$1 [NC]
This doesn't change the url. Can something see what i do wrong?
You need one additional rule to change the URL externally. This should be placed in root .htaccess:
RewriteEngine On
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/([^/]+)/edit\.php\?id=([^\s&]+) [NC]
RewriteRule ^ %1/edit/id/%2? [R=302,L,NE]
RewriteRule ^([^/]+)/edit/id/([^/.]+)$ $1/edit.php?id=$2 [NC,L,QSA]
Give this a try and see how it works for you.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/edit/id/([^/.]+)$ $1/edit.php?id=$2 [NC,L]
</IfModule>
OR you can do this if you only have a couple of directories the same. The will go in the root .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(profiles|customers|test)/edit/id/([^/.]+)$ $1/edit.php?id=$2 [NC,L]
</IfModule>
Related
I want to rewrite the URLs from:
https://www.example.com/bibliorafturi/?wpsolr_fq%5B0%5D=pa_culoare_str%3AAlbastru
to this:
https://www.example.com/bibliorafturi/Albastru
Another example:
https://www.example.com/bibliorafturi/?wpsolr_fq%5B0%5D=pa_culoare_str%3AAlbastru&wpsolr_fq%5B1%5D=pa_brand_str%3AESSELTE
to this
https://www.example.com/bibliorafturi/Albastru/?wpsolr_fq%5B1%5D=pa_brand_str%3AESSELTE
So I need only pa_culoare_str to be SEO friendly.
How can I do this with .htaccess?
UPDATE:
This is my .htaccess file now:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} /(.*)/(.*)/(.*)/?$
RewriteRule ^ /%1?wpsolr_fq[%3]=pa_culoare_str:%2 [QSA,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Thank you!
I'm trying to append to wordpress an additional parameter into my URL.
For example, I have the URL: http://example.com
I want to change that to URL: http://example.com/this-example/
I'm thinking I can do this is in htaccess along the lines of a rewrite condition, but i'm unsure how to go about this. This is what I was thinking here.
Htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteEngine on
RewriteRule ^/this-example/(.*)/ /index.php?$1 [L]
</IfModule>
Options -Indexes
You can try this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{THE_REQUEST} !^/this-example [NC]
# use your own host here, for me is 192.68.10.10
RewriteCond %{HTTP_HOST} 192\.168\.10\.10$ [NC]
RewriteRule !^this-example/ /this-example%{REQUEST_URI} [L,R,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^this-example/(.*)$ $1 [L,QSA]
</IfModule>
Options -Indexes
I would like to change "/" to "/folder".
So when user clicks link with this url "/page.php" I want it to be automatically translated by .htaccess to "/folder/page.php".
How can I achieve this?
This simple rule should work for you in site root .htaccess (parent directory of folder):
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/folder/ [NC]
RewriteRule .* folder/$0 [L]
Please use .htaccess file. i think its better for you.
Your Need is:
HTTP://YOUR_DOMAIN.COM/page.php
TO
HTTP://YOUR_DOMAIN.COM/FOLDER/page.php
Step1:
create an .htaccess file on your Server
Filename: .htaccess
just Copy this part and Change the Values.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} YOUR_DOMAIN.COM$ [NC]
RewriteCond %{HTTP_HOST} !FOLDER
RewriteRule ^(.*)$ http://YOUR_DOMAIN.COM/FOLDER/$1 [R=301,L]
Reference-1 |
Reference-2
Try this:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /folder/$1 [QSA,PT,L]
RewriteRule ^$ /folder/$1 [QSA,PT,L]
RewriteRule ^index.php/(.*) $1 [QSA,R,L]
</IfModule>
I created a folder named folder1 after entering the root. At that level of directory there's my .htaccess, I googled and I paste the following line at
..
RewriteRule ^index\.php$ - [L]
// this
RewriteCond %{REQUEST_URI} !(folder1|folder2|folder3) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
..
But when I go to mydomain.com/folder1, it returned 404 of my wordpress?
You should post all of your code so that we can make sure there aren't other rules conflicting. Not just the part you can't get working.
Try using THE_REQUEST and try it this way and put it above your wordpress rules. So if it matches then do nothing.
RewriteCond %{THE_REQUEST} ^(GET|POST) /(folder1|folder2|folder3) [NC]
RewriteRule ^ - [L]
I found this, exclude subfolder with wordpress .htaccess and workds for me.
I put this before WordPress rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/yoursubdirectoryname1/(.*)$
RewriteRule ^.*$ - [L]
</IfModule>
and here is WordPress rules:
# 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]
</IfModule>
# END WordPress
My complete .htaccess code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/yoursubdirectoryname1/(.*)$
RewriteRule ^.*$ - [L]
</IfModule>
# 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]
</IfModule>
# END WordPress
source: I found this code on WordPress forum.
The main site runs WordPress with .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I'm going to create an CodeIgniter app in subdirectory site.com/online/
If simply add CI .hta file in subfolder it wouldn't work. CI .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|img|styles|js)
RewriteRule ^(.*)$ /index.php?/$1 [L]
Is it possible to combine two .htaccess files or to do something with .htaccess in CI subfolder?
Thank you.
UPD.
Thank you for answers, I've tried all variants, and eventually moved project to subdomain.
First thing, your .htaccess should be like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} !^GET\s/+online/ [NC]
RewriteRule . /index.php [L]
</IfModule>
#Then add this for CI handling in the same .htaccess
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !index\.php [NC]
RewriteRule ^online/(.*)$ online/index.php?/$1 [L,NC]
Then you can remove (or rename) .htaccess in the online subfolder.
Try this for the codeigniter .htaccess:
RewriteEngine on
RewriteBase /online
RewriteCond $1 !^(index\.php|robots\.txt|img|styles|js)
RewriteRule ^(.*)$ /index.php?/$1 [L]
Otherwise all requests to that subfolder would be redirected down to wordpress.
Are you setting AllowOverride? According to the docs you need to allow FileInfo overrides for mod_rewrite.