How to copy functionality of RewriteRule & RewriteBase - .htaccess

I have the following at the document root of my server i.e. www.doodle.com/.htaccess
Options +MultiViews
ErrorDocument 404 /x/404.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^view/([a-f0-9]{40})/$ ./view/index.php?profile_id=$1
</IfModule>
This produces the following:
www.doodle.com/view/32e3234eafsd/
Say I wanted to copy the exact functionality within a sub directroy i.e. www.doodle.com/x/
and produce the following:
www.doodle.com/x/view/3223433242/
Notice the /x/ subdirectory, Am I missing a simple trick here?
Can you help with a solution?
Thanks

Just add the /x/ subdirectory:
RewriteRule ^x/view/([a-f0-9]{40})/$ /x/view/index.php?profile_id=$1 [L]
If you wanted to copy the htaccess file into a directory named "x", then you need to modify your rewrite base:
Options +MultiViews
ErrorDocument 404 /x/404.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /x/
RewriteRule ^view/([a-f0-9]{40})/$ view/index.php?profile_id=$1 [L]
</IfModule>
and get rid of the ./ in front of the rule's target.

Related

mod_rewrite not working with my simple url

The problem is that I cannot make my URL change with the mod_rewrite, the URL I have is this:
http://example.org/files/news.php?news=180
I wish to see something like this:
http://example.org/files/news/180
I've tried these code (every single commented RewriteRule):
# Do not remove this line, otherwise mod_rewrite rules will stop working
# RewriteBase /
ErrorDocument 404 http://mysite.org/notfound.php
Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /files/
#RewriteRule ^(.*)/ news.php?news=$1
#RewriteRule ^/news/([0-9]+) /news?news=$1
#RewriteRule ^(.*)/ files/news.php?news=$1 [L]
RewriteRule ^(.*)/(.*)/ news.php?news=$1 [L]
And nothing, How do the code should look like?? thanks
Place this code in /files/.htaccess:
ErrorDocument 404 http://mysite.org/notfound.php
Options +Indexes +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /files/
RewriteRule ^news/([^/.]+)/?$ news.php?news=$1 [L,QSA]

Having much trouble with mod_rewrite

I'm having some problems in my .htaccess file.
I would like to display the content of this URL:
http://mywebsite.com/admin/payments/invoices/view/index.php?id=123456
When I access this one:
http://mywebsite.com/admin/payments/invoices/view/123456/
Here's my actual .htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteBase /admin/payments/invoices/
RewriteRule ^/view/([0-9]+)/(index.php)?$ /view/index.php?id=$1 [L,QSA]
Do you have any idea?
Thanks!
If you do have the view directory, then the easiest thing is to put this .htaccess in that directory (i.e. {DOCUMENT_ROOT}/admin/payments/invoices/view/.htaccess):
Options +FollowSymlinks
RewriteEngine On
RewriteBase /admin/payments/invoices/view
RewriteRule ^(\d+)$ index.php?id=$1 [L,QSA]
The index.php in the left side hand of the RewriteRule is not required (actually, I expect it not to work: the DirectoryIndex should not yet have been injected in the URI at this stage - unless some other RewriteRule is in effect?), nor is the / at the end of the RewriteBase.
I tested the above on Apache/2.2.21, but the module rules are the same for later versions.
Try this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^.*admin/payments/invoices/view/index\.php\?id=([0-9]+) admin/payments/invoices/view/$1/index.php [L]
</IfModule>
Try putting this in the htaccess file in your document root:
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)id=([0-9]+)
RewriteRule ^admin/payments/invoices/view/index\.php$ /admin/payments/invoices/view/%1/index.php [L]
So when you enter http://mywebsite.com/admin/payments/invoices/view/index.php?id=123456 in your browser's URL address bar, you will get served the content at /admin/payments/invoices/view/123456/index.php. Since it's completely unclear what you actually want, in case you wanted it the other way around:
RewriteEngine On
RewriteRule ^admin/payments/invoices/view/([0-9]+)/(index.php)?$ /admin/payments/invoices/view/index.php?id=$1 [L,QSA]

.htaccess rewrite url to arguments

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^products/([a-zA-Z]+)/([0-9]+)/$ index.php?product=$1&price=$2
This code makes
http://www.example.com/products/computer/1000
into
http://www.example.com/index.php?product=computer&price=1000.
Is it possible to make
http://www.example.com/scriptName/arg1/val1/arg2/val2/arg3/val3
into
http://www.example.com/scriptName.php?arg1=val1&arg2=val2&arg3=val3?
The user should be able to give an unlimited number of arguments. This way one can have /index.php?page=forum&subforum=subforum&quote1=postNo1&quote2=postNo43 and so on rewrite /index/page/forum/subforum/subforum/quote1/postNo1/quote2/postNo43
How would the .htaccess code look?
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]+)/([^/]+)/([^/]+)(.*?)/?$ $1/$4?$2=$3 [L,QSA]
RewriteRule ^([^/]+)/$ $1.php [L]
This will forward a URI of /scriptName/arg1/val1/arg2/val2/arg3/val3 to /scriptName.php?arg3=val3&arg2=val2&arg1=val1

change url .htaccess php

I have a page name page.php and my url as localhost/mysite/page.php , now how can i change the url using .htaccess file to localhost/mysite/somethinghere1/somethinghere2/page.php
It tried using the below code but it doesn't work out.
<IfModule mod_rewrite.c>
# Enable Rewriting
RewriteEngine On
# Rewrite user URLs
# Input: user/NAME/
# Output: user.php?id=NAME
RewriteRule ^somethinghere1/somethinghere2/.php? page.php
</IfModule>
how can i acheive this.
What about this:
RewriteRule ^somethinghere1/somethinghere2/([^/\.]+).php/?$ page.php
Use it like this:
RewriteRule ^(mysite/)somethinghere1/somethinghere2/(.*\.php)/?$ $1$2 [L,NC]
Also make sure this in .htaccess file in your DOCUMENT_ROOT directory.
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([^/]+)/([^/]+)/page.php /page.php?first=$1&second=$2 [NC]
This is the basic code , you can play with it to fit your needs like the following edit :
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([^/]+)/([^/]+)/([^/]+) /$3.php?first=$1&second=$2 [NC]
So x/y/z would be z.php?first=x&second=y

.htaccess - Virtual Directory for a single predefined file

How would be the .htaccess lines to make a Virtual Directory from a single php File?
www.domain.de/file.php should go to www.domain.de/file/
Not all php files, only a single predefined in this Case the file.php
Thanks!
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^file.php$ file/ [L]
</IfModule>
This is how I solved it:
DirectoryIndex index.php
RewriteEngine on
RewriteRule ^file/ file.php [L]
Options -Indexes

Resources