URL Rewriting (Mod_Rewrite) - mod-rewrite

Hi I know absolutely nothing about mod_rewrite.
I'm asking how I could rewrite this URL as needed.
website.com?page=pagename&content=contents&action=download
as
website.com/pagename/contents/download
the param "action" will not always be set. Unsure if that makes a difference.

Try adding this to the htaccess in your document root:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /?page=$1&content=$2&action=$3 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ /?page=$1&content=$2 [L,QSA]

Related

How to rewrite url to omit one parameter

I have the following url. I want to rewrite the following url to omit the "view" from the url.
Here is currently my existing mod rewrite
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
http://example.com/page/view/helloworld
How do i rewrite the url to make it
http://example.com/page/helloworld
the keyword helloworld is dynamic.
Expert advice appreciated.
You might want to add the R=301 into the flags if you are worried about transfering SEO.
RewriteEngine On
RewriteRule ^(.+)/view/(.+)$ /$1/$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]

rewriterules remove .php in the middle of url

I'm having trouble rewriting url from /video.php/test-video to /video/test-video
I currently use:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
#RewriteRule ^/video/(.*)$ /video.php?/$1 [L]
I already rewrite index.php/url-with-white-list to /url-with-white-list.
Now I've had a video.php file that uses url from a database.
I just would like to rewrite video.php/url-of-the-video to video/url-of-the-video to
My rewrite of index.php works but I can't make my rewrite of video.php works.
Any ideas ?
By advance, thanks a lot !
Any suggestion ?
Thanks by advance
Solutions :
RewriteCond %{REQUEST_URI} ^(.*)video/(.*)
RewriteRule (.*)video/(.*)$ /video.php?/$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

CodeIgniter - Routing doesn't work

I have a routing problem in CodeIgniter.
I can access to my default controller (the login page) with the http://localhost/MySite. So I think the routing configuration is good.
When I submit the login form of my login page, I get a Not found error 404 and the URL displayed is http://localhost/MySite/login?
When I insert "index.php" (http://localhost/MySite/index.php/login) in the url, it works. In the documentation it's written that I must add some lines in .htaccess:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L,QSA]
What is wrong with this URL Routing?
Try this thing which i am using write now in my project........
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Please try this..
RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
I hope it will be ok.

Mod Rewrite rules for a subdirectory

I have a drupal installation set up in a subdirectory of a domain (www.mydomain.com/cms), but I'm having trouble getting the queries to format correctly using mod_rewrite. I need url requests coming in as:
{domain}/cms/admin/content/node
to be interpreted as:
{domain}/cms/?q=admin/content/node
Here's what I have:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} ^/(cms/.*)$
RewriteRule ^(.*)$ cms/?q=$1 [L,QSA]
Any pointers on where I'm going wrong?
Where these rules you posted are located? If you create a .htaccess inside the "cms" directory with the following content, I believe it should work fine:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

A little help on a mod_rewrite expression

I need a very quick fix in a mod_rewrite expression for drupal we have
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
But i need to redirect the value of the subdomain in get too so i need something that will give:
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?subdomain=THE SUBDOMAIN HERE&q=$1 [L,QSA]
Don't know how to do it, please help!
Trying this again, for some reason my code isn't rendering properly.
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{HTTP_HOST} ^(.*)\.mydomain\.com$
RewriteRule ^(.*) index.php?subdomain=%1&q=1 [L,QSA]
Based off of some forum posts I found here.
You don't really need the subdomain in the query string.
The subdomain can be found in PHP in $_SERVER['SERVER_NAME'].
PHP documentation says:
'SERVER_NAME'
The name of the server host under which the
current script is executing. If the script
is running on a virtual host, this will be
the value defined for that virtual host.

Resources