I need to rewrite my url
http://midogames.com/game.php?id=%D9%84%D8%B9%D8%A8%D8%A9%20%D8%B5%D8%A7%D8%A6%D8%AF%20%D8%A7%D9%84%D8%B0%D9%87%D8%A8
to
http://midogames.com/%D9%84%D8%B9%D8%A8%D8%A9%20%D8%B5%D8%A7%D8%A6%D8%AF%20%D8%A7%D9%84%D8%B0%D9%87%D8%A8
"please note they are spaces in the link"
i am doing this
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+) /game.php?id=$1 [NC,L]
</IfModule>
but it did not work with me, any suggetion
Try with NE flag:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+game\.php\?id=([^\s&]+) [NC]
RewriteRule ^ /%1/? [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/?$ game.php?id=$1 [NE,L,QSA]
Related
i use htaccess
Options +FollowSymLinks
RewriteEngine on
# Rules
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule detalhe/(.*) detalhe.php?id=$1
i want redirect:
https://example.com/detalhe.php?ID=31&URL=lorem-to-lorem
to:
https://example.com/31/lorem-to-lorem.html
any ideias to help?
You may use an additional rule to handle additional URI segment:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/detalhe\.php\?ID=(\d+)&URL=([^\s&]+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(\d+)/(.+)$ detalhe.php?ID=$1&URL=$2 [L,QSA,NC]
RewriteRule ^detalhe/(.*) detalhe.php?id=$1 [L,QSA,NC]
I want so show A custom page for example sub.php , whenever a url is not found
for example
http://domain.com/blabla/
http://domain.com/blabla/bladas.html
http://domain.com/tedabad/dasd/sadsad/
So above are all the examples of not found urls , Which I would like to display contents of http://domain.com/sub.php , I tried below code , but its not working
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/?$ /sub.php [L]
RewriteRule ^([^/]+)/(.+?)/?$ /$1/sub.php [L]
You can check for presence of sub.php in a RewriteCond and use an ErrorDocument directive:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1/sub\.php -f [NC]
RewriteRule ^([^/]+)/(.+?)/?$ /$1/sub.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /sub.php [L]
I have downloaded and installed http://www.question2answer.org/ on my website on http://www.yourstartups.com/discussion/ (discussion sub-directory)
Current url structure is like: example.com/index.php?qa=123&qa_1=why-do-birds-sing
I want to change to /123/why-do-birds-sing
(why-do-birds-sing is example query)
Following is my htaccess:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
</IfModule>
Can anyone help me?
You need a new rule to rewrite your pretty URL.
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?qa=$1&qa_1=$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0 [L,QSA]
</IfModule>
I'm trying to write a RewriteCond to my htaccess file to catch only URL's that DO NOT end with a / .
This is my file so far:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ ./wedding.php?w=$1
So I'm trying to pass the "W" GET var only if the URL does NOT end with /
So this will not be rewritten:
domain.com/bla/
But this will:
domain.com/bla
Please assist
Cheers!
Answer:
This is what I ended up using:
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ ./wedding.php?w=$1
Edit For Howlin:
This is my full htaccess, I have wordpress and a web app living together on the same dir, so if the URL isnt for the webapp it will go to Wordpress:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ ./wedding.php?w=$1
# 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
This should work for you:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([A-Za-z0-9]+)$ /wedding.php?w=$1 [R]
The above should only redirect urls that don't exist and don't have a / at the end.
It is possible to rewrite my url using mod_rewrite and htaccess where a user could enter:
http://www.mainsite.com/12345
which the server would translate as:
http://www.mainsite.com/index.php?ID=12345
By also trying to remove the file extension from all pages, (remove .php) it conflicts and causes a never ending redirect:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)\.php$ $1 [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9a-zA-Z]+)$ index.html?ID=$1 [QSA,NC,L,R]
</IfModule>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)$ index.php?ID=$1