Mathieu Delvaux
Mathieu Delvaux

Reputation: 68

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!

Upvotes: 0

Views: 70

Answers (3)

LSerni
LSerni

Reputation: 57418

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.

Upvotes: 1

Jon Lin
Jon Lin

Reputation: 143936

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]

Upvotes: 0

Stelian Matei
Stelian Matei

Reputation: 11623

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>

Upvotes: 0

Related Questions