i have found a solution here, which I am looking for
Creating dynamic URLs in htaccess
so basically I modified the given htaccess code (following code is from solution)
RewriteRule ^products/([A-Za-z0-9-])/?$ /view.php?mode=prod&title=$1
I changed it to fit my needs to
RewriteRule ^blog/([A-Za-z0-9-])/?$ /blog.php?id=$1
but when I visit the url localhost/blog/1 it gives me 404 Error, that's the only line in my .htaccess file, what I am doing wrong?
You say that's the only line in your .htaccess, don't you have this one too (just before yours) ?
RewriteEngine On
you .htaccess should contain at least :
RewriteEngine On
RewriteRule ^blog/([A-Za-z0-9-])/?$ /blog.php?id=$1
Related
This is my first time using .htaccess and currently my .htaccess file is redirecting to my custom 404 page. This is being handled with the following line in my .htaccess file:
ErrorDocument 404 /404.html
On top of this, I need to rewrite a few urls so that /addition/ points to /includes/addition.html (this is one example). So I add the following:
RewriteEngine On
RewriteRule /addition/ /includes/addition.html
But this then serves me a 500 error when Is hold be getting 404 error. On top of this, when I point to mysite.com/addition/ the browser isn't fetching addition.html from my includes folder.
Would someone please explain to me how to have these two rules working without effecting the other, and correct my secondary rewrite rule?
Danke.
Have it this way in your site root .htaccess:
ErrorDocument 404 /404.html
RewriteEngine On
RewriteRule ^/?([a-z]+)/?$ /includes/$1.html [L,NC]
I am trying to get .htaccess to fetch the page http://www.example.org/aa/exists.php when http://www.example.org/aa/doesntexist.php is entered in the URL bar. The .htaccess file is clearly functional, because the DirectoryIndex line is producing the desired result, with http://www.example.php in the URL bar fetching the page http://www.example.php/aa/default.php.
I tried adapting the response to how to redirect using HTTP_REFERER on htaccess to my situation, but without success.
Below is the full text of my .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_REFERER} ^(.*)www\.example\.org/aa/doesntexist\.php [NC]
RewriteRule ^(.*)(www\.example\.org/aa/)doesntexist\.php(.*)$ $1$2exists.php$3 [NC,L]
DirectoryIndex aa/default.php
</IfModule>
A request for http://www.example.org/aa/doesntexist.php yields the following error:
Not Found
The requested URL /aa/doesntexist.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Try adding Options +FollowSymlinks and Allow Override All as first commands before turning the engine on.
I couldn't see anything wrong in your condition or rule. I recently had a very similar problem that could be solved that way.
If that's not the problem, you might have a look at http://forum.modrewrite.de/topic82.html
It's in German, unfortunately, but maybe stil helpful - at least by aid of google translate (surely not perfect, but good enough).
Btw.: if there is a reason for checking the referrer and not only the requested URI, keep it. Else, the rule alone will do what you want. There is no need for a condition if the content of the condition matches the pattern of the rule.
I had this rewrite rule set up in .htaccess and it was all working fine...
Options +FollowSymLinks +ExecCGI
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/mypage(.*)$ [NC]
RewriteRule ^(.*) http://example.com/PHProxy/poxy-0.5b2/index.php?url=http://example.org/mypage [L,R=302,NC]
However, when I change the url in the RewriteRule to
http://example.com/PHProxy/poxy-0.5b2/index.php?url=http://example.org/mypage it still redirects to the old URL.
After some research, I added a syntax error into the .htaccess file to check the .htaccess file was being used (and indeed it was - as it resulted in an Internal Server Error when you tried to load a page from that directory).
There seems to be some caching somewhere, but I'm not sure. Any ideas why my change is not being picked up / how to troubleshoot and resolve?
Problem solved. Just noticed that there is a mypage subdirectory which still contained the old rewrite rule, so that was the one being executed.
I currently want my site to rewrite from
.com/page/1234
to
.com/?view=page&id=1234
Heres my .htaccess content:
RewriteBase /
RewriteRule ^/page/([0-9]+)$ /index.php?view=page&id=$1
ErrorDocument 404 errors/404.html
When I type ".com/page/1" my site just redirects to the 404 page.
What have I done wrong? I tried to the simplest:
RewriteRule ^/page$ /about.php
But it doesn't work either. So I'm having some suspect that 000webhost (my current host) is not supporting RewriteRule although they stated they support it.
From personal experience, I know they -do- support RewriteRule, but it is somewhat horrible to test them. In "per-directory"-context, the slash from a directory is appended to the "prefix" part of the url. .htaccess always works as in "per-directory"-context. A RewriteRule that begins with a slash in .htaccess will therefore never match anything.
If you change your .htaccess to the following, everything should work as expected:
RewriteBase /
RewriteRule ^page/([0-9]+)$ /index.php?view=page&id=$1
ErrorDocument 404 errors/404.html
I recommend reading the documentation for mod_rewrite. It contains a lot of useful information.
SO I have this in my .htaccess file
RewriteEngine On
RewriteBase /core/
RewriteCond %{QUERY_STRING} ^page=([0-9]+)$
RewriteRule ^page page/%1/? [L]
my url is
http://localhost/core/page.php?page=8
with the rules applied I'm getting..
Not Found
The requested URL /core/page/8/ was not found on this server.
This is running on wampserver 2.2
the file structure looks like
c:/wamp/www/core
the .htaccess is inside the /core/ directory.
What is it that I'm missing.. i've checked my apache.conf file and it looks fine.
I think you got it the wrong way around. When logically thinking of rewriting you don't rewrite original URL to new URL (for example page.php?page=8 to page/8/) you actually rewrite page/8/ to page.php?page=8. You tell the server how it should interpret the unfamiliar URL.
So if I understood correctly what you want to achieve is:
User visits localhost/core/page/8/
User is served (under the hood) localhost/core/page.php?page=8
I believe the following RewriteRule will do the trick (The query string condition is not necessary):
RewriteRule ^page/(\d+)/$ page.php?page=$1 [L]