I'm trying to add a new rule in the htaccess file that will allow input of other instead of the actual name of the page which is notify. But I can't seem to get it to work.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^other$ notify [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Also tried something like:
RewriteRule ^other$ index.php/notify [QSA]
and this:
RewriteRule ^other$ /index.php/notify [QSA]
Also tried adding the rules from wordpress itself (inside the admin_init section of a plugin) and then refresh the rules by going to the permalinks settings, choosing post name and then save but no luck either. Upon checking htaccess file it produced a rule similar to the above one:
add_rewrite_rule('other', 'index.php/notify', 'bottom');
I've verified that I can override the rules via the htaccess file in the root directory because when I tried to use an actual file in the server hello.php
RewriteRule ^other$ hello.php [QSA]
It works. I just don't know why when I use a wordpress page it doesn't work. It also seems to work when I use the absolute path:
RewriteRule ^other$ http://somesite.com/notify [QSA]
But this is no good because when I add some arguments to the URL (which is what I will ultimately do) I end up with bad looking URL when I do the above: http://somesite.com/?some_argument=some_value
The current permalink setting in wordpress is set to post name. Any ideas what I have missed?
Try this rule:
RewriteRule ^other/?$ index.php?p=PAGE_ID [QSA]
Put the necessary PAGE_ID to redirect to
Hello may be you can use .htaccess plugin..! to control it from admin panel. I hope this Help you
http://wordpress.org/plugins/wp-htaccess-control/
Related
I am trying to make a URL go to a file which is a WordPress page template.
I am doing a website that has categories and subcategories then a details page.
First off I am try to make.
www.example.com/explore/category_name
The category_name is dynamic and pulled from a non WordPress database.
I am trying to get that any time the URL is www.example.com/explore/whatever. It points to /wp-content/themes/my_theme/myfile.php
Here is my .htaccess file.
RewriteEngine On
RewriteBase /
RewriteRule ^explore/([a-z0-9-]+)$ /wp-
content/themes/visitsi_theme/listing-page.php [NC]
#BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteRule ^explore/([a-z0-9-]+)$ /wp-
content/themes/visitsi_theme/listing-page.php [NC]
You need to include the L flag to prevent the WP directives that follow being processed. I would also remove NC flag and make the "whatever" match A-Z if required. Otherwise, /ExPlOrE/ would be accepted (rather than generating a 404). This directive is also split across two lines (in the middle of the substitution) - although maybe that's a typo? (But it certainly needs fixing.)
So, try the following instead:
RewriteRule ^explore/([a-zA-Z0-9-]+)$ /wp-content/themes/visitsi_theme/listing-page.php [L]
visitsi also looks like a typo - but maybe that's intentional?
Providing /wp-content/themes/visitsi_theme/listing-page.php is a physical file, then the WP front controller should ignore it.
I have a site in wordpress in which a page is showing questions based on its ID.
http://example.com/index.php/question/?questionid=9&title='how-to-rewite-htaccess'
I am the beginner to php I'm not able to graps other examples found on stackoverflow.com
Here's my .htaccess code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^/question/([^/]*)/([^/]*)/$ /question/?questionid=$1&title=$2 [NC,L]
</IfModule>
But this is not working. please tell where is error.
Since your using Wordpress you can turn on permalinks which takes care of the url friendly urls for you see https://codex.wordpress.org/Settings_Permalinks_Screen.
Login to your admin then go to permalinks and set a preferred style.
example.com/index.php/question/9/how-to-rewite-htaccess doesn't match your rewrite rule because the rule has a trailing /. Change the regex (first) part of your rewrite rule to:
^/question/([^/]*)/([^/]*)/?$
Adding ? makes the trailing / optional.
Once you go to setting > permalinks and set the pretty links, WordPress will automatically generate .htaccess based on the setting you choose. Don't forget to save.
More information here http://www.wpbeginner.com/beginners-guide/why-you-cant-find-htaccess-file-on-your-wordpress-site/
I've taken over a former site/domain, and set up a new site using Wordpress. The WP installation rewrites URL's to static ones, as you'd expect it to.
At the same time I want to preserve the former pages, as they have incoming links. I'm not interested in 301'ing them to "new" pages.
The old URL structure is /index.php?id=123, which I suspect is causing the problem with the WP .htaccess file. For reference, this is what it looks like:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I've tried adding the following:
RewriteRule ^([0-9]+).html index.php?id=$1 [R,L]
Doesn't work. Just redirects to site.com/?id=123 and shows the front page.
I should add that I plan on just adding these new pages as regular static HTML files in the format of 123.html, 321.html etc.
How do I use .htaccess to make this work together with the WP installation and what WP puts into the .htaccess file?
To clarify:
I want to have my 123.html static HTML page be index.php?id=123. When you access index.php?id=123 it should bring up 123.html, but show index.php?id=123 in the address bar. If you access 123.html it should 301 to index.php?id=123.
To map an URL with a querystring up to an actual file you'll need to use a RewriteCond to match the querystring itself (as RewriteRule doesn't):
Something along these lines ought to do it:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# retrieve X.html when index.php?id=X is requested
RewriteCond %{REQUEST_FILENAME} index\.php
RewriteCond %{QUERY_STRING} ^id=([0-9]+)$
RewriteCond %1.html -F
RewriteRule .* %1.html? [L]
# standard WordPress routing
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
This will first check to see if you've got a request for index.php with a querystring like id=X.
Then it'll check to see if a file called X.html actually exists; I'm not 100% happy about having to use the more system hungry subrequest file check -F rather than the standard -f but I can't see a way around it in .htaccess in this case.
If X.html actually exists, it'll fetch that file whilst leaving the URL as index.php?id=X.
However if that file doesn't exist it'll fall back to standard WordPress no file, no directory routing to index.php
I'm not a WordPress expert but that should work; I guess the main WordPress controller uses $_SERVER['REQUEST_URI'] to determine the action.
Note: This won't, however, prevent people from accessing 123.html directly by going to the URL www.site.com/123.html - I kept falling into infinite loops and Apache 500 errors trying to prevent that :|
I want to redirect domainA.com/folder/ which originates within an older wordpress installtion to domainB.com/folder1/folder2/ which is the link to the page within my new wordpress installation wihtout the url changing.
I have managed to achieve this with the .htaccess file inside domainA.com/folder/ which reads:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/folder
RewriteRule ^(.*)$ http://www.domainB.com/folder1/folder2/ [P]
The Rewriterule [P] (proxy) flag does what I want and redirects the page without changing the url but some of the content within my Enfold WP template such as the advanced layer slider and icons fail to load.
I assume this error is due to some sort of conflict with WP's native htaccess code and I also suspect it has to do with the lines:
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
I have experimented with adding the first, third and fourth lines to my code but it doesnt work. Does anybody know how I could resolve this issue?
If it makes any difference the wordpress site I want to direct to (domainB.com/folder1/folder2/) is one whithin a Wordpress Network.
For the moment I have changed the [P] flag to [L] flag which redirects and works but changes the url.
Any help or advice would be much appreciated. Thank you!
Try to change the paths of images (the URLs) in advanced layer slider and icons URLs from
relative to absolute ones (as described in RFC 2396), then you can use the [P] flag in .htaccess again.
Often plugins uses relative paths when outputting content, but this can cause such type of troubles.
This following code takes care of permalinks in WorPress and it is recommended to keep the beginning and ending WordPress lines so that WordPress is able to locate it and modify it as needed. You may already have all this and are just not displaying it. I do not know.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
In the other section you probably need to remove the trailing / after folder2 like so:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/folder
RewriteRule ^(.*)$ http://www.domainB.com/folder1/folder2 [P]
Okay I'm trying to use Lando (landocms.com) and I'm trying to get the pretty urls option to work.
Basically by default Lando creates link like: domain.com/index.php/page. Supposedly, there is a way to remove the index.php so the links become: domain.com/page. I have created an .htaccess as directed, however it does not work.
Here is the .htaccess I am using:
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I have tried alot of variations, /index.php/, index.php? and plenty more but none work. According to HostGator everything should be fine. Any thoughts? I think I'm going crazy haha.
Thanks!
Rewriting for a CMS is a two-tier approach. First, you need to set your .htaccess (I have put a safer one here for you):
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .+ index.php [QSA,L]
Then, LandoCMS allows you to remove the index.php from the generated addresses, by means of turning on the appropriate setting in the administration panel. See this link for more information.
If the .htaccess content I've given you doesn't work, then simply use the one that the CMS has given you.
You want to remove the index.php part from any URL, but process the incoming, friendly URLs through index.php nevertheless
RewriteEngine On
# remove index.php and redirect client
RewriteCond %{ENV:REDIRECT_SEO} ^$
RewriteRule ^/?index.php/(.*) /$1 [R,L]
# process friendly URL
RewriteCond %{REQUEST_URI} !^/index.php/
RewriteRule .+ /index.php/$0 [E=SEO:1,L]
The environment setting E=SEO:1 prevents an endless loop.