I've searched the web and I tried to solve problem but I could not figure out how.
I'd like to redirect dizisozluk.net/words to dizisozluk.net/ne-demek/anlami/words and change plus (+) sign to dash (-) sign. For example
dizisozluk.net/family+tree
to
dizisozluk.net/ne-demek/anlami/family-tree
My old code is here
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{THE_REQUEST} /search\.php\?word=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ search.php?word=$1 [QSA,L]
How can I change this?
Thanks in advance.
Have it this way:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} !\s/+ne-demek/anlami/ [NC]
RewriteRule (.*) https://%{HTTP_HOST}/ne-demek/anlami/$1 [R=301,L,NE]
RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule .* https://www.%1%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{THE_REQUEST} /search\.php\?word=([^\s&]+) [NC]
RewriteRule ^ /ne-demek/anlami/%1? [R=301,L]
# recursive rule to replace space by - from URI OR query string (anywhere)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*?)(?:\+|%20|\s)+(.+?)\sHTTP [NC]
RewriteRule ^ /%1-%2 [L,NE,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ne-demek/anlami/(.+)$ search.php?word=$1 [QSA,L]
Related
This code below for rewrite/redirect from localhost/moneyworld/exchange?title=BTC_PMUSD to localhost/moneyworld/BTC_PMUSD but i want to rewrite/redirect from www.domain.com/exchange?title=BTC_PMUSD to www.domain.com/BTC_PMUSD Without also /moneyworld/
RewriteEngine ON
RewriteCond %{THE_REQUEST} \s/(moneyworld)/exchange\?title=([^\s]*)\s [NC]
RewriteRule ^ /%1/%2 [NE,QSD,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ /moneyworld/exchange?title=$2 [L]
Thanks
The problem was that i was forwarding exchange.php to exchange after the url rewrite rules so simply the code below solved it
RewriteEngine ON
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} \s/exchange\?title=([^\s]*)\s [NC]
RewriteRule ^ /%1 [NE,QSD,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /exchange?title=$1 [L]
with this code and clean URL like (example.com) I could add www and remove id in url.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?id=$1 [L]
RewriteCond %{THE_REQUEST} ^GET\ /(.*/)?(?:index\.php)?\?id=([^\s&]+) [NC]
RewriteRule ^ /%1%2? [R=301,L]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
But now my root of website is in a folder.
so my new url is www.examole.com/newfolder
how can add newfolder to top code?
You can use this .htaccess in /newfolder:
RewriteEngine On
RewriteBase /newfolder/
RewriteCond %{THE_REQUEST} ^GET\ /(.*/)?(?:index\.php)?\?id=([^\s&]+) [NC]
RewriteRule ^ %1%2? [R=301,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?id=$1 [L,QSA]
current URL:
domain/index.php?id=p123
I want:
add www
remove:index.php
remove 'id' form URL
I do it this way:
RewriteCond %{THE_REQUEST} /(?:index\.php)?\?id=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?id=$1 [L]
RewriteCond %{THE_REQUEST} /(?:index\.php)?\?id=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L,NE]
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
it works if domian is without sub directory.
how can I change this code to support sub directory too like this:
domian/subdirectory/index.php?id=p123
I'll go about it this way:
First, redirect non-www URLs to www ones:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Rewrite the friendly URLs to respective index.php files:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*/)?([^/]+)$ /$1index.php?id=$2 [L]
Next, handle the raw URIs with index.php in them:
RewriteCond %{THE_REQUEST} ^GET\ /(.*/)?(?:index\.php)?\?id=([^\s&]+) [NC]
RewriteRule ^ /%1%2? [R=301,L]
The last rule will also take care of URLs like domain.com/dir/?id=sth and domain.com/dir/index.php?id=sth
You can accomplish this with the following changes:
RewriteCond %{THE_REQUEST} \ /(.*/|)(?:index\.php)?\?id=([^\s&]+) [NC]
RewriteRule ^ /%1%2? [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index\.php
RewriteRule ^(.*/|)([^/]*)$ $1index.php?id=$2 [L]
We know that %{THE_REQUEST} has the format GET /path/to/index.php?id=12312412 HTTP/1.1 or something along those lines. In the first rule we match \, which is a literal space, then the beginning slash that is always there. (.*/|) will match everything until index.php, or exactly nothing. The same trick we do in the second rule. I have added RewriteCond %{REQUEST_URI} !index\.php to prevent an infinite loop when index.php does not exist for a particular directory.
I am trying to rewrite the url example.com/parts/toolbucket/part.php?id=1 into example/toolbucket/part/1
I have most of the .htaccess working but the last part of the rewrite doesn't work.
This is my .htaccess
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} \s/parts/([^\s]+)\s [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /parts/$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
RewriteRule ^toolbucket/([0-9]*)$ ./part.php?id=$1
Any ideas?
Because you are missing the directory part in the rule. If you want your URL to be this example.com/toolbucket/part/1
Replace this
RewriteRule ^toolbucket/([0-9]*)$ ./part.php?id=$1
With this.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^toolbucket/part/([0-9]*)/?$ /parts/toolbucket/part.php?id=$1 [L]
I have these rules, everything work good.
I just need to add this rule:
from it.domain.org/index.php?city=newyork to it.domain.org/product-usa-newyork
The only thing that change is "newyork". It can be also: lasvegas etc..
Try inserting these 2 rules before your existing rules:
#Rewrite from http://it.domain.org/index.php?city=dc to http://it.domain.org/product-usa-dc
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^[^.]+\.domain\.org$ [NC]
RewriteCond %{THE_REQUEST} \s/+index\.php\?city=([^\s&]+) [NC]
RewriteRule ^ /product-usa-%1? [R=302,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^[^.]+\.domain\.org$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^product-usa-([^/]+)/?$ /index.php?city=$1 [L,QSA,NC]
Put it at the start
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^[^.]+\.domain\.org$ [NC]
RewriteCond %{THE_REQUEST} \s/+index\.php\?city=([^\s&]+) [NC]
RewriteRule ^ /product-usa-%1 [R=302,L]