how to rewrite this simple url? - mod-rewrite

how can i rewrite
www.mysite.com/someURLhere
into
www.mysite.com/ping.php?url=someURLhere
without mistaking local files, and directories as domains.
so i dont want
www.mysite.com/index.php
www.mysite.com/admin/
to rewrite to
www.mysite.com/ping.php?url=index.php
www.mysite.com/ping.php?url=admin/

<VirtualHost *:80>
ServerName yoursite.com
DocumentRoot /www/yoursite
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /ping.php?url=$1 [L,QSA]
</VirtualHost>
If this is a .htaccess file you dont need %{DOCUMENT_ROOT} in both instances.

Related

Rewrite rules for several laravel apps in the same Virtual Host

I have an Apache2 virtual host where I'll be hosting several Laravel applications.
The VH document root is /home/user/applications/portal.
The laravel applications are in:
/home/user/applications/portal/larapps/larapp1
/home/user/applications/portal/larapps/larapp2
...
I want the URLs to be like:
http://portal.com/larapp1/...
http://portal.com/larapp2/...
So this is my config:
<VirtualHost *:80>
ServerName portal.com
DocumentRoot /home/user/applications/portal
Alias /larapp1 /home/user/applications/portal/larapps/larapp1/public
<Directory /home/user/applications/portal/larapps/larapp1/public>
RewriteEngine On
RewriteBase /larapps/larapp1/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php [L]
</Directory>
</VirtualHost>
If the request is http://portal.com/larapp1 then the route that matches is as I expect: Route::get('/',...).
But, inexpectedly, if I add any URI in the request, it doesn't do what I want. For example, if the request is http://portal.com/larapp1/foo, it doesn't match Route::get('/foo',...) but Route::get('/larapp1/foo',...).
What should I do so that routes are matched without the prefix /larapp1?
I found it! My bad, I did a mistake in the configuration: I used a filesystem path in RewriteBase, when I should have indicated a base URI. This is the right config:
<VirtualHost *:80>
ServerName portal.com
DocumentRoot /home/user/applications/portal
Alias /larapp1 /home/user/applications/portal/larapps/larapp1/public
<Directory /home/user/applications/portal/larapps/larapp1/public>
RewriteEngine On
RewriteBase /larapp1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php [L]
</Directory>
</VirtualHost>

mod_rewrite for Typical CMS-style Redirect

Is there a specific RewriteRule that would work for Magento and convert
http://<domainname>/index.php/<filename>
into
http://<domainname>/<filename>
According to phpinfo(), Loaded Modules lists mod_rewrite , so it appears to be enabled.
Here is the relevant section from .htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
</IfModule>
Any suggestions?
So it turns out that it wasn't a missing mod_rewrite rule. I fixed it by inserting the Directory section below into /etc/apache2/sites-available/dev.magecom.local.conf (The Directory section didn't exist at all in the previous version).
<VirtualHost *:80>
ServerName dev.magecom.local
ServerAlias www.dev.magecom.local
DocumentRoot /var/www/sites/dev.magecom.local/public_html/
<Directory /var/www/sites/dev.magecom.local/public_html/>
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Codeigniter Cannot Remove index.php after move to virtual host

I created the virtual in wamp server. Everything is working but i can't able to remove the index.php. I don't know how to write the .htaccess.
Here is the details
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot E:/Projects/OnGoing/bonanza/dev.bonanza.com
ServerName dev.bonanza.com
<Directory "E:/Projects/OnGoing/bonanza/dev.bonanza.com">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
and my htaccess
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Allow these directories and files to be displayed directly:
# - index.php (DO NOT FORGET THIS!)
# - robots.txt
# - favicon.ico
# - Any file inside of the media/ directory
RewriteRule ^(index\.php|robots\.txt|favicon\.ico|media|uploads|js|css|images|plugins|source|files|fonts|lib|plugins) - [PT,L]
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php?/$0 [PT,L,QSA]
Did you setup your host file correctly to read the path of your site? For me I used this all the time works fine in development server.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

Redirect to alternate url using the variable declared after first slash

Ok, Ive checked this site and still I am confused about how to do this...
I need to take a url like this
subdomain.domain.com/1234
and redirect to a url like this
http://assets.subdomain.domain/php/store.php?store_num=1234
utilizing the numbers after the slash as a get variable
Here is what I have in my .conf file so far.
<VirtualHost *:80>
ServerName assets.subdomain.domain.com
ServerAlias subdomain.domain.com/*
VirtualDocumentRoot /var/www/html/prod/subdomain.domain.com/assets/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://assets.subdomain.domain/php/store.php?store_num=$1 [L,QSA]
</VirtualHost>
As a side note, my .conf file is pretty big and has a lot of other vhosts in it, so I'm not sure if this isn't working because there is something else in the .conf file that is overwriting it.
You need to enable mod_rewrite by adding a RewriteEngine directive.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://assets.subdomain.domain/php/store.php?store_num=$1 [L,QSA]

Rewrite everything to be after index.php/

I'm setting up a php mvc framework and I want to redirect anything after the domain to index.php/$1 but it's not working. I have rewrite_module enabled and AllowOverride All, is there something else I'm missing?
Basically I want the url to go from this http://www.example.com/foo/bar to http://www.example.com/index.php/foo/bar so I can grab it from $_SERVER['PATH_INFO']
Here's what I have...
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]
httpd-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot c:/wamp/www
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "c:/websites/snugglemvc"
ServerName www.snugglemvc.com
<Directory "c:/websites/snugglemvc">
Order Deny,Allow
Allow from all
AllowOverride all
</Directory>
</VirtualHost>
I believe you need the leading slash on /index.php as your regex matches beginning of line.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/$1 [L]
it was an issue with my httpd.conf file. i didn't have AllowOverride all on the localhost. once I changed that everything worked.

Resources