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]
Related
I want to make my website temporarily accessible only at example.com/unfinished-version.
All URLs like /style/main.css or /public/style/main.css would point to /soon.html, then all URLs like /unfinished-version/style/main.css would point to URLs like /public/style/main.css.
The rule I wrote doesn't work, because /public/style/main.css or /public/some-page still works.
RewriteRule ^(?!unfinished-version).*$ soon.html [L,NC]
URLs like example.com/gibberish show soon.html, so it does partly work.
I'll show you full .htaccess, although I find it unnecessary. (The rules shouldn't interfere with this, plus the L flag should avoid processing of any further rules in the first place.)
.htaccess in the root:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(?!unfinished-version).*$ soon.html [L,NC]
RewriteRule ^unfinished-version(.*)$ public/$1 [L,NC]
</IfModule>
.htaccess in public/:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]
</IfModule>
P.S.: Not even RewriteRule ^(.*)$ soon.html [L,NC] works.
I have a directory structure like root/user/confirm/index.php
I want to make redirect like
Redirect this url
http://www.site.com/user/confirm/ASd2sasda4ass
To this
http://www.site.com/user/confirm/index.php?confirm=ASd2sasda4ass
I am trying this way
RewriteRule /user/confirm/([^A-Za-z0-9])$ /user/confirm/index.php?confirm=$1 [L,QSA]
It redirects this url properly
http://www.site.com/user/confirm/index.php/ASd2sasda4ass
To
http://www.site.com/user/confirm/index.php?confirm=ASd2sasda4ass
But not working for this url without index.php
http://www.site.com/user/confirm/ASd2sasda4ass
It shows 404 not found error
Please see and suggest any possible way to do this.
Thanks.
UPDATE
Complete codes
Options +FollowSymlinks
RewriteEngine on
<IfModule mod_rewrite.c>
RewriteRule /user/confirm/([^A-Za-z0-9])$ /user/confirm/index.php?confirm=$1 [L,QSA]
</IfModule>
Try this (without confirm.php in the url. You shouldn't need it anyway):
RewriteRule ^user/confirm/(.*)/? user_confirm.php?confirm=$1 [L]
I solved this issue by removing this rewrite rule from root .htaccess
RewriteRule ^/user/confirm/([^A-Za-z0-9])$ /user/confirm/index.php?confirm=$1 [L,QSA]
And placing another .htaccess file in confirm directory to hide index.php and processing query parameter there with following codes.
Options +FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?confirm=$1 [L]
</IfModule>
And now its working without index.php in url. Hope this helps others too with same issue.
I just transfered my Domain to a new Server. Mod_Rewrite is enabled on the new server but unfortunately some RewriteRules don't work, while others do. I haven't changed anything in the .htaccess
So the URL www.mydomain.com/go/10.html should make an internal redirect to www.mydomain.com/go.php?name=10
The snippet in the .htaccess looks like this:
# go.php
RewriteRule ^go$ "$0/" [R=301,L,QSA]
RewriteRule ^go/$ go.php [L,QSA]
RewriteRule ^go/.*?([^\.\/]*)\.html$ go.php?name=$1 [L,QSA]
The $_GET["name"] is not available if I call this url.
Replace your .htaccess code with this.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(go)/([^.]+)\.html$ /$1.php?name=$2 [L,QSA,NC]
I don't work to much with mod_rewrite so I could easily be just missing something simple. I want to match and replace a specific URL. The URL I want to rewrite would look like this:
http://www.sample.com/hello to http://www.sample.com/index.php?page=hello
My htaccess currently has the following rule in place:
RewriteRule ^(hello)/?$ index.php?page=$1 [L]
However, when I implement the rule and I test it by trying to go to http://www.sample.com/hello or http://www.sample.com/hello/ I always get my 404 error document. ugh I feel like it should be simple and I must be missing something right there. Any help would be fantastic and much appreciated!
Here is my whole file for reference:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?sample\.com/ [NC]
RewriteCond %{REQUEST_URI} !hotlink\.(gif|png) [NC]
RewriteRule ^(.*)\.(gif|jpe?g|png)$ sample.com/hotlink.png[R,NC,L]
RewriteCond %{HTTP_HOST} ^www.sample\.com$ [NC]
RewriteRule ^(.*)$ http://sample.com/$1 [R=301,L]
RewriteRule ^(hello)/?$ index.php?page=$1 [L]
Thanks
Your code works perfeclty fine for me. Maybe you're missing
RewriteEngine On
RewriteRule ^(hello)/?$ page.php?page=$1 [L]
or maybe mod_rewrite is not installed or loaded at all.
Look for
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
in your main apache configuration file httpd.conf
This is one of those times...
I cleared the htaccess file and only used the following couple lines and tested it out:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /
#
RewriteRule ^(hello)/?$ page.php?page=$1 [L]
I realized looking at the non custom 404 page that it referenced page.php and not index.php!
Not Found
The requested URL /page.php was not found on this server.
So turns out with all my edits I mistakenly typed page.php in the rule instead of index.php. I corrected it and the rule works. One of those times :)
Thanks all!
I have created a site in a subdirectory and would like the site to appear as if it's in the root.
I used the below Mod_Rewrite code to get the site root to redirect to the subdirectory, but I would like the folder the files are held in to not appear.
currently: www.example.com/sitefiles/content/
Would like: www.example.com/content
Thanks
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^$ /sitefiles/ [L]
RewriteRule (.*) /sitefiles/$1 [L]
If it needs to be done via .htaccess and mod_rewrite, then use this:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/sitefiles/
RewriteRule (.*) /sitefiles/$1 [L]
Since you do not explicitly specify the page when website root will be hit, then there is no need for this line: RewriteRule ^$ /sitefiles/ [L]
You need to add condition for your main rewrite rule to prevent rewrite loop (when already rewritten URL gets rewritten again): RewriteCond %{REQUEST_URI} !^/sitefiles/
Well, the directory should have no reason to appear in any listing, and that mod_rewrite you posted should allow you to do as you said. Still, I would go about it a different way:
Options +FollowSymLinks +Indexes
RewriteEngine on
RewriteBase /
RewriteRule ^$ sitefiles/ [L]
RewriteRule ^(.+)$ sitefiles/$1 [L]
Hope this works.