long story short:
This is my (sub-) domain and file:
https://sub.domain.com/test.php
And I would love to have it like:
https://sub.domain.com/test
My .htaccess file looks like this:
RewriteEngine On
RewriteBase /
RewriteRule ^test/?$ test.php [NC,L]
But I always get a 404 not found.
The strange part: When I change ^test/?$ to ^test/test/?$ and try to get to https://sub.domain.com/test/test.php everything works fine.
I have no idea what to do, I searched like a maniac -- maybe someone has a solution?
(btw the subdomain points to a different directory than domain.com; so there are no nested folders like sub.domain.com -> domain.com/sub)
Thanks :)
Edit: Server is running Apache/2.4.25 (Debian)
Related
I want to add rewriterules that works in local environment (localhost) and on my liveserver.
Why?
I don't want to change rules when I test my project locally and upload it to the liveserver.
Adding Rules
Here an example
(ANY-URL)index.php?page=somepage
change to
(ANY-URL)/somepage
So I used a rewritemod generator and pasted this into it:
index.php?page=somepage
The rewriterule I got, looks like this: (of course my .htacces starts with RewriteEngine On)
RewriteRule ^([^/]*)$ /?page=$1 [L]
When I try to get to (http:)
//localhost/myproject/development/index.php?page=login it sends me to the root directory of my local development envirment. But the URL in the adressline doesn't change.
Testing
Of course I tried some other Rules by pasting the whole URL into the generator just to test if the rewrite thing works.
Also here the URL doesn't change to short-url but the server cant find stylesheets and javascripts anymore. I got redirected to the index.php
Possible solutions?
Maybe it has something todo with that "RewriteBase"?
Do i have to set a basepath?
My .htacces is located here:
//localhost/myproject/development/.htaccess
Later I also want to change paths that look like this:
(ANY-URL)index.php?page=somepage&second=hello&third=world&fourth=cool
Also here a I'm looking for a solution that works on both environments.
Since the htaccess is located inside a sub-directory, use RewriteBase:
RewriteEngine On
RewriteBase /myproject/development/
Once that is done, you use the base element in your php/html files. This will resolve the addresses for the scripts/stylesheets in your pages.
<base href="/myproject/development/" />
Now, the rewrites in htaccess would be:
RewriteRule ^((?!index\.php)[^/]+)/?$ index.php?page=$1 [L]
I have a file that is located at:
http://www.mydomain.com/alcamino/includes/display_objects/custom/camino-tools/RemotingService.cfc
I would like to be able to access RemotingService.cfc like this:
http://www.mydomain.com/remoting/RemotingService.cfc
I have tried several different Rewrite rules but none are working correctly.
Can anyone point me in the right direction?
Thanks
Try adding this in the htaccess file in your document good
RewriteEngine On
RewriteRule ^/?remoting/RemotingService.cfc$ /alcamino/includes/display_objects/custom/camino-tools/RemotingService.cfc [L]
I have a folder named "keywords" for my website, such as this: http://www.mysite.com/keywords/
In the folder I only have an index.php file. Regardless of what someone types in after the folder, I need the index.php to show. For example, http://www.mysite.com/keywords/this-is-a-test should show the index.php file's content but without changing the URL.
Everything I've tried seems to fail - I'm working with the .htaccess in my /keywords/ folder. Regardless of what I put there I seem to keep getting a 404 error. Any help would be appreciated, I'm sure it's something small and simple that I just don't know how to do.
This is what I currently have:
RewriteEngine on
RewriteRule - index.php [L]
The problem with this is that it only work when going to links with a dash in them.
For example,
http://www.mysite.com/keywords/testing-this
does work. But this does not work:
http://www.mysite.com/keywords/testingthis
Any help would be appreciated.
RewriteEngine On
RewriteBase / #make sure your website is located in root directory, if not you have to add directory here...
RewriteRule ^keywords/testingthis$ /keywords/index.php$1 [L]
I'm just going to explain my problem here :
http://mysite.com/movie/20000
should be rewritten to
http://mysite.com/movie.php?id=20000
my htaccess file :
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^movie/([0-9]+)$ movie.php?id=$1
On my localhost WAMP installation this works fine, but when I put it online on my linux host it doesn't completely work. It does go to the movie.php page, but it seems it gives no GET parameter id.
Edit :
if I use
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^movie([0-9]+)$ movie.php?id=$1
then
http://mysite.com/movie20000
Goes to the correct page, but I would like /movie/20000 and not just /movie20000
It also seems that my host automatically rewrites a visit to mysite.com/movie to mysite.com/movie.php
After searching for a long time, and pulling some of my lovely hair out I found the solution.
I just added
Options -MultiViews
to my htaccess file and that fixed it.
Why? Because .php was being added to urls without an extension, which I really did not need.
This should work.
RewriteRule ^movie/([0-9]+)$ http://mysite.com/movie.php?id=$1 [NC,L]
Don't forget the [NC, L] it means Case insensitive, last rule... If you don't, it will continue to process through your htaccess rules, maybe triggering other ones.
Still, the stuff below is good advice.... :)
Check to see if the Rewrite module is loading with apache. Look for this line in the httpd.conf file:
LoadModule rewrite_module modules/mod_rewrite.so
Check to see if your apache config allows for .htaccess files for your system or in the virtual host definition.
Also, test with a simpler rewrite catch all and test that alone to see if it's working at all like this (get rid of everything else in your htaccess file to limit the test):
RewriteEngine On
RewriteRule ^(.*)$ http://www.google.com [L,R=301]
Any request to your site should go to google if the configuration for apache is correctly set.
I'm working on my project and now I want to transfer it from my localhost to server. Everything seems to work fine, but .htaccess doesn't work.
The server should be suporting mod_rewrite and print_r(apache_get_modules()); shows mod_rewrite running.
But still, when I type myaddress.com/contact, it shows error 404.
Here is the .htaccess file, but it should be fine, since it runs on my localhost:
RewriteEngine on
RewriteRule ^adminator/?$ adminator/login.php [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&detail=$2 [L]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
Do you have any idea?
Thanks, Mike.
Does the server allow .htaccess? It doesn't really have to.
Try other directives, ask your hosting provider, or check the configuration yourself if possible.
I tried testing your rules they should be fine on urls such as: http://myhost.com/test1 and http://myhost.com/test1/test2 result in requesting url: index.php?page=test1 and index.php?page=test1&detail=test2
So the problem is not your rules, it is your server setup somewhere. As Mewp said check your Apache config file, look for AllowOverride which should be enabled for .htaccess files to overriding default settings.
Ok, fixed it .. deep in the hostings settings, there was an option to activate it .. but I found it after 4 hours of looking around .. :P