mod_rewrite and GoDaddy - .htaccess

I really have only a fair idea of what I am doing. Sorry.
This is what I did to rewrite URLs like these:
http://example.com/foo/bar/news/1-category-name/2-item-name
http://example.com/foo/bar/news/1-category-name
into these:
http://example.com/foo/bar/news.php?newsID=2
http://example.com/foo/bar/news-categories.php?categID=1
respectively
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /foo/bar
RewriteRule ^news\/([^\/]+)/([0-9]+)-([^\/]+)$ news.php?newsID=$3
RewriteRule ^news\/([0-9]+)-([^\/]+)$ news-categories.php?categID=$1
</IfModule>
But whenever I try this URL:
http://example.com/foo/bar/news/16-news-category-1/11-title
It always returns a 404 error:
The requested URL /foo/bar/news.html/16-news-category-1/11-title was not found on this server
Why is it trying to find news.html? What am I doing wrong?
I don't know if this is relevant but example.com is virtual (I really don't know the term). The actual files can also be accessed via http://real-domain.com/qux/. So you'd do http://real-domain.com/qux/foo/bar/news/1-category-name/2-item-name to get to 2-item-name.
Does it also help to say that this script actually runs on my development machine?
Development:
PHP v5.3.5
Apache v2.2
Live:
PHP v5.3.6
Apache v2.2

You this code in your .htaccess:
RewriteEngine on
RewriteRule ^news/([0-9]+)-([a-z\-]+)-([0-9]+)/([0-9]+)-([a-z\-]+)(\/?)$ /news.php?newsID=$4 [L,NC]
RewriteRule ^news/([0-9]+)-([a-z\-]+)/([0-9]+)-([a-z\-]+)(\/?)$ /news.php?newsID=$3 [L,NC]
RewriteRule ^news/([0-9]+)-([a-z\-]+)-([0-9]+)(\/?)$ /news-categories.php?categID=$1 [L,NC]
RewriteRule ^news/([0-9]+)-([a-z\-]+)(\/?)$ /news-categories.php?categID=$1 [L,NC]
so when someone goes to:
news/11-category-12 or
news/11-category-12/ or
news/11-category or
news/11-category/
it goes to: news-categories.php?categID=11
and when someone goes to:
news/11-category-12/1-title or
news/11-category-12/1-title/ or
news/11-category/1-title or
news/11-category/1-title/
it goes to: news.php?newsID=1
Also, make sure the .htaccess is at the root of the public_html folder as well of news.php and news-categories.php

Related

Can I redirect all old non-query string url's to new url

I want to redirect all old url's which have a format of 'domain.com/property-search/ref-R3265882' to the format of 'domain.com/services/properties/for-sale/property/?ref=R3265882' but can't seem to get it to work
I have tried:
RewriteRule ^property-search/ref-$ /services/properties/for-sale/property/?ref=$1 [R=302,L]
and also
RewriteRule ^property-search/(.*)$ /services/properties/for-sale/property/?ref=$1 [R=301,NC,L]
I am wanting to redirect all reference number with the old format to the new format.
Solution found (adding above in htaccess if using wordpress):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^property-search/ref\-([a-zA-Z0-9-]+)$ /services/properties/for-sale/property/?ref=$1 [R,L]
</IfModule>
This should do what you describe:
RewriteEngine on
RewriteRule ^/?property-search/ref-(R\d+)$ /services/properties/for-sale/property/?ref=$1 [R=301]
It is a good idea to start out with a 302 redirection first and only change that to a 301, once you are happy with the result. That prevents caching issues while you are still playing around.
That rule will work likewise in the http servers host configuration or in a dynamic configuration file (".htaccess") located in the http host's document root, if the interpretation of such files is enabled and the rewriting module is loaded... You should prefer to use the real http server configuration in all cases you can, though, dynamic configuration files have a lot of disadvantages.
I was able to sort it by doing this above wordpress current htaccess entries:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^property-search/ref\-([a-zA-Z0-9-]+)$ /services/properties/for-sale/property/?ref=$1 [R,L]
</IfModule>

htaccess and Laravel

my domain
example.com
I want install Laravel to subfolder
example.com/my_app
when I pass the link
example.com/my_app/public - I see page "You have arrived", but I want see this page without segment "public".
I want make something like I do when I use Laravel not in subfolder, like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
I edited .htaccass file in base folder (example.com) :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/my_app
RewriteRule ^(.*)/$ my_app/public/$2 [L,R=301]
</IfModule>
after this when I pass at example.com/my_app/ I redirects to example.com/my_app/public and I see page "You have arrived", but this is redirect (R=301) and if I delete flag R=301 - I see page with "Whoops, looks like something went wrong."
I am three days looking solutions in this website, but ...
tell me what am I doing wrong.
Thank.
The entry point for all requests to a Laravel application is the public/index.php.
for further info you can go to this link.
Assuming you are using Apache, You would need to configure virtual host for this as you would need to point example.com/my_app to your laravel/public/index.php. directory.

Rewrite URL to get contents from sub-directory

I have edited my /etc/hosts file to link domain.com to my localhost. Now when I visited domain.com I want it to get the site contents from domain.com/site/ but only using the URL domain.com thus removing site/ from the URL.
I have done this once before, so I know it's possible, but I lost the code. Can someone please assist me? .htaccess scripting is not my strong. Apologies if this is a duplicate of something else.
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^((?!site/).*)$ site/$1 [L,NC]
I have managed to get this working with the following code:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !(.*)your_directory
RewriteRule ^(.*)$ your_directory/$1 [L]

Using .htaccess and mod_rewrite

I'm having some mod_rewrite problems with my .htaccess..
RewriteBase /folder
RewriteEngine on
Rewrit­eRule ^(.*)$ basic.p­hp?­url=$1 [L]
Above is what I'm currently using. However, I have no idea what I'm doing to be honest as I'm just cycling through the internet trying to figure this out.
Basically, for my website, if you type in
www.domain.com/folder/xxx/
I want it to basically be www.domain.com/folder/basic.php?url=xxx.
For some reason, all that does is cause a 404 error :/
So can someone please politely point me in the right direction?
Ok, I will explain using your htaccess.
RewriteEngine on
Turn on the Rewrite Module to enable URL rewriting
RewriteBase /folder
Rewrite the Base Directory to directory name folder
RewriteRule ^folder/(.*)$ basic.php?url=$1 [L]
Remap every request make using the folder/***** to basic.php?url=********
Note: RewriteEngine On Should be the first statement on your case
RewriteEngine on
RewriteBase /
RewriteRule ^folder/(.*)$ folder/basic.php?url=$1 [L]
This is more of a problem with regexs than .htaccess files.
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
http://www.regular-expressions.info/

CakePHP and .htaccess in shared hosting environment

Greetings!
I have CakePHP based app on shared hosting I wonder if there's a way to clean up the url through .htaccess. What bugs me is that I have to have index.php in it or I get a 404:
project.com/index.php/controller/method
Initially I was getting a 404 error no matter what and my host admin ended up setting RewriteEngine off and this is what it looks like now
<IfModule mod_rewrite.c>
RewriteEngine off
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Is there fix for this without the .htaccess? As it is right now, does it pose any type of security risk?
Thanks
You need three .htaccess files :
/.htaccess
/app/.htaccess
/app/webroot/.htaccess
If the one you pasted in your question is the one at the root of your website, that's probably where your problem comes from. These directives file would rewrite URLs to project.com/webroot/, which doesn't exist. It should redirect to project.com/app/webroot/, which will in turn rewrite to index.php?url=$1 (relative to project.com/app/webroot/).
I'm not pasting the files here; the three of them are available in the CakePHP releases as well as in the Book: http://book.cakephp.org/2.0/en/installation/url-rewriting.html (check the 3rd item in the page).
Are you sure the mod_rewrite module is enabled on your shared hosting?

Resources